dimanche 22 septembre 2019

Ionic Laravel Upload

Any good example to upload image from ionic to laravel api

Any help will be appreciated

I tried the below but the file is not transfer to public directory of laravel

  uploadPic() {


    const fileTransfer: FileTransferObject = this.transfer.create();

    let options: FileUploadOptions = {
      fileKey: "photo",
      fileName: "test3.jpg",
      chunkedMode: false,
      mimeType: "image/jpeg",
      headers: {}
    }

    fileTransfer.upload(this.base64var, 'http://127.0.0.1:8000/api/choices/imagedata/', options).then(data => {
      alert(JSON.stringify(data));
    }, error => {
      alert("error");
      alert("error" + JSON.stringify(error));
    });
  }

Laravel

public function imagedata(Request $request){
      //dd($request-all());
        $destinationPath = 'images/';
        $newImageName='MyImage.jpg';
        $request::file('photo')->move($destinationPath,$newImageName);
        return $this->sendResponse($request->all(), 'Images uploaded succesfully');

    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire