尝试将文件URL发布到DB时为什么会出现500错误?

时间:2019-10-13 23:27:40

标签: javascript php reactjs laravel debugging

我不知道为什么在尝试将文件URL发布到数据库时出现500错误。在我的日志中,这表示我的控制器不存在,但确实存在。我在做什么错,我该如何解决?

注意:我正在使用from PyQt5.QtCore import Qt, QDateTime from PyQt5.QtWidgets import * from PyQt5 import QtGui class ParentWindow(QDialog): def __init__(self): super(ParentWindow, self).__init__() self.cw = None self.button = QPushButton('Go to child') self.button.clicked.connect(self.child) layout = QHBoxLayout() layout.addWidget(self.button) self.setLayout(layout) self.show() def child(self): self.cw = ChildWindow(self) self.hide() def parent(self): self.cw.close() self.show() class ChildWindow(QDialog): def __init__(self, parent): super(ChildWindow, self).__init__(parent) self.button = QPushButton('Go to parent') self.button.clicked.connect(self.parent().parent) layout = QHBoxLayout() layout.addWidget(self.button) self.setLayout(layout) self.show() if __name__ == '__main__': import sys app = QApplication(sys.argv) window = ParentWindow() sys.exit(app.exec_()) 运行该项目。我尝试将其切换并使用valet open,但仍然收到相同的错误。

这是我的控制器:

php artisan serve

这是我的路线:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class FileuploadController extends Controller {

    public function store(Request $request) {
        if($request->get('file')) {
            $image = $request->get('file');
            $name = time().'.' . explode('/', explode(':', substr($image, 0, strpos($image, ';')))[1])[1];
            \Image::make($request->get('file'))->save(public_path('images/').$name);
        }

        $fileupload = new Fileupload();
        $fileupload->filename=$name;
        $fileupload->save();

        return response()->json('Successfully added');
    }
}

这是我的发帖请求(react.js)

<?php

Route::get('/', function () {
    return view('welcome');
});

Route::post('/', 'FileuploadController@store');

这是日志中的错误:

import React, { Component } from 'react';
import axios from 'axios';

export default class FileUploadComponent extends Component
{
    constructor(props) {
        super(props);
        this.state ={
            image: ''
        };
        this.onFormSubmit = this.onFormSubmit.bind(this)
        this.onChange = this.onChange.bind(this)
        this.fileUpload = this.fileUpload.bind(this)
    }

    onFormSubmit(e){
        e.preventDefault();
        this.fileUpload(this.state.image);
    }

    onChange(e) {
        let files = e.target.files || e.dataTransfer.files;
        if (!files.length)
            return;
        this.createImage(files[0]);
    }

    createImage(file) {
        let reader = new FileReader();
        reader.onload = (e) => {
            this.setState({
                image: e.target.result
            })
        };
        reader.readAsDataURL(file);
    }

    fileUpload() {
        const url = '/';
        axios.post(url).then(response => {
            console.log(response);

            this.setState({
                file: this.state.image
            });
        });
    }

    render() {
        return(
            <form onSubmit={this.onFormSubmit}>
                <h1>React js Laravel File Upload Tutorial</h1>
                <input type="file"  onChange={this.onChange} />
                <button type="submit">Upload</button>
            </form>
        )
    }
}

0 个答案:

没有答案