2015-10-14 42 views
2

我在AngularJS新,我试图上传与图像NG文件上传意外场NG-文件上传

我的任务是翻译的离子应用的web应用程序,所以我有重复使用相同的路线。

<button ngf-select="upload($file)" ng-model="file">Select</button> 


    $scope.upload = function (file) { 
     $scope.event.headerPictures.push(file); 
     console.log($scope.event); 
     console.log(file); 
     if (file && !file.$error) { 
     Upload.upload({ 
      url: $config.baseUrl + '/api/event/upload-picture', 
      method: "POST", 
      headers: {"Authorization" : "token=" + userService.getToken()}, 
      file: file, 
     }).then(function (resp) { 
      console.log('Success ' + resp.config.data.file.name + 'uploaded. Response: ' + resp.data); 
     }, function (resp) { 
      console.log('Error status: ' + resp.status); 
     }, function (evt) { 
      var progressPercentage = parseInt(100.0 * evt.loaded/evt.total); 
      console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name); 
     }); 
     }; 
    }; 

我仍然得到同样的错误与许多不同的syntaxe:

Error: Unexpected field 

谁能告诉我我失去了什么?

+0

你得到什么错误? – danial

+0

错误来自哪里?哪条线?是否在选择等之前上传? – danial

+0

嗨Danial,错误来自POST完成。一旦文件被发送,我就可以在服务器控制台中获得它。 – Thounder

回答

0

对不起,在一个答案猜测,但与一个意想不到的字段错误我认为你的代码行与额外的逗号分隔符是问题。

file: file,应该file: file

希望这有助于。我会评论这一点,但我的声誉太低,评论仍然:)