【发布时间】:2016-08-23 12:12:52
【问题描述】:
我正在使用 angularjs,我正在尝试将图片与请求正文中的其他数据一起上传到 django 后端服务器。
我不断收到来自服务器的错误消息,告诉我我发送的图片不是文件。 (假设后端没有问题)
我尝试使用 ng-file-upload (https://github.com/danialfarid/ng-file-upload) 来获取文件,然后通过 Angular 本身发送它。 (注意:我需要将其他数据与图片一起发送)所以我想将文件存储在一个变量中并将其传递到请求正文中,如下所示:
<form name="form">
<div class="button" ngf-select ng-model="file" name="file" ngf-resize="{width: 100, height: 100}">Select</div>
<button type="submit" ng-click="submit()">submit</button>
</form>
由于文件存储在$scope.file中,我尝试在http请求中使用:
$http({
'method': "PUT",
'url': "api/candidate-profiles/" + id,
'data':data
})
数据在哪里:
{"id": $scope.id,
"name": $scope.name,
"avatar":$scope.file}
我从后端收到一个验证错误,指定头像不是文件。有什么帮助吗?
【问题讨论】:
标签: javascript angularjs http