简体   繁体   English

Angular ng-file-upload方法PUT不起作用

[英]Angular ng-file-upload method PUT not working

I'm using https://github.com/danialfarid/ng-file-upload for handle my uploading file. 我正在使用https://github.com/danialfarid/ng-file-upload来处理我的上传文件。

But i got problem when i'm using method: "PUT". 但是我在使用方法“ PUT”时遇到问题。

  Upload.upload({
      url: APIROOT + 'categories/' + $routeParams.id,
      data: data,
      method: 'PUT'
  }).then(function (response) {
       ResultService(response.data);
   }, function (response) {
       ResultService(response.data);
   }).finally(function () {
       $scope.loading = false;
       $scope.button_text = "Update";
   });

my API Code just simply (laravel 5.1) : 我的API代码很简单(laravel 5.1):

   dd($request->all());

At my server i can't receive the data. 在我的服务器上,我无法接收数据。 But if i change method to "POST" i can receive it properly. 但是,如果我将方法更改为“ POST”,则可以正确接收它。

Any solution? 有什么办法吗?

This is not an issue related to "laravel". 这与“ laravel”无关。 You are not able to receive the data which has been sent using "PUT" method because "ngFileUpload" module internally uses "Form" to upload image with or without data and Form supports only two methods "POST" & "GET". 您无法接收使用“ PUT”方法发送的数据,因为“ ngFileUpload”模块内部使用“ Form”上载有或没有数据的图像,并且Form仅支持“ POST”和“ GET”两种方法。

Please refer the following link for more clarification... Using PUT method in HTML form 请参考以下链接以获取更多说明... 以HTML形式使用PUT方法

Solution: 解:

extend data form with {_method: 'PUT'} so Laravel will detect it want PUT method. 使用{_method: 'PUT'}扩展数据形式,以便Laravel检测到它需要PUT方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM