您好我在AngularJS中使用以下代码上传图片:
HTML:
//inject angular file upload directive.
angular.module('myApp', ['ngFileUpload']);
var MyCtrl = [ '$scope', 'Upload', function($scope, Upload) {
$scope.onFileSelect = function($files) {
//$files: an array of files selected, each file has name, size, and type.
for (var i = 0; i < $files.length; i++) {
var $file = $files[i];
Upload.upload({
url: 'src/assets',
file: $file,
progress: function(e){}
}).then(function(data, status, headers, config) {
// file is uploaded successfully
console.log(data);
});
}
}
}];
JS:
{{1}}
当我运行它并尝试上传图片时,我收到此错误:
&#34;无法加载资源:服务器响应状态为405(方法不允许)&#34;
所以它抱怨POST方法将文件保存到目标文件夹中,这显然是不允许的,任何想法???或者有人有一种更简单的方法将图像上传到网站文件夹中?非常感谢 !!
答案 0 :(得分:0)
现在已经排序了, 问题是URL错了,在查看在服务器端上传的Controller / ActionMethod之后,我意识到要调用的url实际上是
myUploads / ImageUpload
我现在可以将图像上传到我的Angular应用程序中,没有任何问题! :)