2016-09-26 99 views
0

我正在處理Ionic角度1應用程序,我想將圖片上傳到我的laravel api服務器。然而,我得到錯誤1(文件未找到?)和laravel PHP錯誤作爲錯誤機構回來。我已經按照多個示例文件上傳這樣,我不斷收到這個錯誤..Cordova文件傳輸錯誤1 Laravel

角代碼:

 $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); 
      } 
     }; 

所以在這裏我存儲我的圖片在一個數組,因爲我想顯示他們在應用程序中,併爲上傳過程建立隊列。

角服務

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); 
    } 

錯誤,我得到:科爾多瓦錯誤代碼1

Laravel錯誤:ErrorException在Factory.php行91:\ N參2傳遞給Illuminate \ Validation \ Factory :: make()必須是在D:\ PROGRAMS \ wamp64 \ www \ ac-laravel \ bootstrap \ cache \ compiled.php中調用的null數組類型的數組,其格式爲

任何想法?也許我不能只將圖像URI提供給上傳過程?

回答

0

發現錯誤,原因是在我的請求模式的規則功能沒有給數組回

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