Невозможно загрузить изображение в проекте laravel - PullRequest
0 голосов
/ 08 июня 2019

Я пытаюсь загрузить изображение из собственного реактивного проекта, используя laravel в качестве основы моей системы. enter image description here -> Это то, что я отправляю с fetch. enter image description here -> Это ошибка, которую я получаю.Это мой код Laravel:

public function upload(Request $request)
  {

    $image = $request->get('data');
    $name = 'Sup.bitch';
    Image::make($request->get('data'))->save(public_path('images/').$name);




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

    return response()->json(['message' => 'Success']);

 }

, и это мой код переднего конца:

myfun = () => {
    ImagePicker.showImagePicker(options, response => {
      console.log("Response = ", response);

      if (response.didCancel) {
        console.log("User cancelled image picker");
      } else if (response.error) {
        console.log("Image Picker Error: ", response.error);
      } else {
        let source = { uri: response.uri };

        this.setState({
          avatarSource: source,
          pic: response.data
        });
      }
    });
  };



uploadPic = () => {
    console.log(this.state.pic);
    alert("ddf");
    fetch(
      "POST",
      "http://192.168.2.45/backend/public/api/upload",
      {
        Authorization: "Bearer access-token",
        otherHeader: "foo",
        "Content-Type": "multipart/form-data"
      },
      [
        // element with property `filename` will be transformed into `file` in form data
        { name: "image", filename: "avatar.png", data: this.state.pic }
      ]
    ).then(resp => {
      console.log(resp.message);
      alert("your image uploaded successfully");
      this.setState({ avatarSource: null });
    });
  };
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...