在Postman中进行测试(将文件发送到API)时,为什么我的简单发布请求不起作用?

I have two separate code bases. React.js on the frontend and Laravel for backend. In my backend code, I'm trying to send a file to the API. However, I keep getting upload_file_not_found. I'm not sure what I'm doing wrong.

同样,代码库是完全分离的,所以我认为这就是我的问题所在,但我不确定。我已经为此撞墙了。

Even if I get rid of Bearer ...., it still gives the same error. What am I doing wrong and how can I fix this?

enter image description here

前端代码:

<form action={this.state.url} method="post" encType="multipart/form-data" className="upload" onSubmit={this.submitHandler}>
  <input type="file" name="fileToUpload" id="fileToUpload" className="fileToUpload" onChange={this.uploadHandler}/>
  <input type="submit" value="Upload Image" name="submit" className="submitBtn"/>
</form>

后端代码:

class FileUploadController extends Controller {
    public function uploadTest(Request $request) {

        if(!$request->hasFile('fileToUpload')) {
            return response()->json(['upload_file_not_found'], 400);
        }
        $file = $request->file('fileToUpload');
        if(!$file->isValid()) {
            return response()->json(['invalid_file_upload'], 400);
        }
        $path = public_path() . '/uploads/images/store/';
        $file->move($path, $file->getClientOriginalName());
        return response()->json(compact('path'));
    }
}
评论