Cordova 文件传输错误 1 ​​Laravel

Cordova File Transfer error 1 Laravel

我正在开发一个 Ionic angular 1 应用程序,我想在其中将图片上传到我的 laravel api 服务器。但是我收到错误 1(找不到文件?)和 laravel php 错误作为错误正文返回。我已经按照多个示例以这种方式上传文件,但我一直收到此错误..

Angular代码:

     $scope.takePicture = function () {
              var options = {correctOrientation: true,
                saveToPhotoAlbum: true,
                encodingType: 0,
                sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
                mediaType: Camera.MediaType.PICTURE,
                destinationType: Camera.DestinationType.FILE_URI};
              getPicture(options);
            };

  var getPicture = function(options) {
          navigator.camera.getPicture(onCapturePhoto, onFail, options);
        };
        function onFail(message) {
          alert('Failed because: ' + message);
            }

 function onCapturePhoto(fileURI) {
              $scope.pictures.push(fileURI);
            }

  $scope.uploadPhoto = function () {
          var repairJobId = 1;
          for(var i=0; i<$scope.pictures.length;i++){
                repairJobService.uploadPhoto($scope.pictures[i],repairJobId);
          }
        };

所以在这里我将我的照片存储在一个数组中,因为我想在应用程序中显示它们并为上传过程制作一个队列。

Angular 服务

 function uploadPhoto(file,repairJobId) {
              var win = function (r) {
                console.log("Code = " + r.responseCode);
                console.log("Response = " + r.response);
                console.log("Sent = " + r.bytesSent);
              };

              var fail = function (error) {
                alert("An error has occurred: Code = " + error.code);
                console.log("upload error source " + error.source);
                console.log("upload error target " + error.target);
                console.log("response code " + error.responseCode);
                console.log("error:  " + JSON.stringify(error));
              };

              // Destination URL
              var url = 'http://192.168.137.1/ac-laravel/public/api/photo/add';

              // File name only
              var filename = file.split("/").pop();
              console.log("filename:"+ filename);

              var headers={'X-Requested-With':'XMLHttpRequest'};

              var options = new FileUploadOptions({
                fileKey: "photo",
                fileName: filename,
                chunkedMode: false,
                headers: headers,
                params : {'repair_job_id':repairJobId} // directory represents remote directory,  fileName represents final remote file name
              });


              var ft = new FileTransfer();
              console.log(file, encodeURI(url));
               ft.upload(file, encodeURI(url),win, fail, options, true);

        }

Laravel 函数:

 public function storeRepairJobPhotos2($request)
   {
       $destinationPath = 'uploads/';
       $newImageName='MyImage.jpg';
       $request::file('photo')->move($destinationPath,$newImageName);
   }

我得到的错误:Cordova 错误代码 1

Laravel 错误:Factory.php 第 91 行中的 ErrorException:\n 传递给 Illuminate\Validation\Factory::make() 的参数 2 必须是数组类型,给定为空,在中调用D:\PROGRAMS\wamp64\www\ac-laravel\bootstrap\cache\compiled.php

有人知道吗?也许我不能只将图片 URI 提供给上传过程?

发现错误,原因是我的请求模型中的规则函数没有返回数组

 public function rules()
    {
        return [
            'photo'          => 'required| mimes: jpg,jpeg,png'
        ];
    }