我是新手,正在尝试使用ng- AngularJS - upload上传图片
我的任务是将Ionic应用程序转换为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);
});
};
};对于许多不同的语法,我仍然得到相同的错误:
Error: Unexpected field谁能告诉我我错过了什么?
发布于 2015-11-06 08:02:54
很抱歉猜测答案,但是有一个意外的字段错误,我认为您的代码行带有额外的逗号分隔符是问题所在。
file: file,应为file: file
希望这能有所帮助。我会评论这一点,但我的声誉太低,仍然无法评论:)
https://stackoverflow.com/questions/33120525
复制相似问题