将图像上传到文件夹资产不起作用

时间:2018-08-09 22:16:20

标签: angularjs file file-upload

当我尝试上传图像并通过方法发布将其发送时,出现此错误: 加载资源失败:服务器响应状态为405(不允许使用方法) 我正在使用angular js,我想上传此imag并将其发送到文件夹资产  我在选择图片时在控制器中使用了此功能

//in my controller
vm.uploadFiles = function(file) {
            debugger
        console.log('file is '+ file );
        console.dir(file);
        var uploadUrl = 'assets';

        fileUploadSrv.uploadFileToUrl(file, uploadUrl);

        };

 // in my service
 (function(){
    'use strict';
  angular.module('WEOPTIM').
    service('fileUploadSrv',['dataManager','api',fileUploadService]);
  function fileUploadService(dataManager,api){


    function uploadFileToUrl(file, uploadUrl){
      debugger
      var fd = new FormData();
      fd.append('file', file);
      for (var key of fd.entries()) {
            console.log(key[0] + ', ' + key[1]);
        }

        fd[key[0]]=key[1];

        return $http.post(uploadUrl, fd, {
                transformRequest: angular.identity,
                headers: {'Content-Type': 'application/json',
                           'Accept':'application/json'
            }
            });

  };


   return{
    uploadFileToUrl:uploadFileToUrl
   }
  };
})();

0 个答案:

没有答案
相关问题