【发布时间】:2018-02-26 01:08:04
【问题描述】:
我正在尝试使用 Form-data 发送文件,但是这个脚本在 angular-4 中不起作用,虽然它在 angular-2 中起作用
var fd = new FormData();
var datas = $("#fileForm").serializeArray();
// send other data in the form
for( var i = 0; i < datas.length; i++ ) {
fd.append(datas[i].name, datas[i].value);
};
// append file to FormData
fd.append("file", $("#fileInput")[0].files[0])
// for sending manual values
fd.append("email", this.email+'');
fd.append("category", this.cate+'');
fd.append("pricepackage", this.pkg+'');
fd.append("duration", this.pkg_d+'');
fd.append("secret_key", this.srt_key+'');
var url = "http://127.0.0.1:8000/func/textfile_sent/";
this.http_obj.post(url,fd, {
headers: {'Content-Type': undefined},
transformRequest : angular.identity
}).success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
transformRequest : angular.identity 处显示错误,错误为:
TS2345:类型参数 '{ headers: { 'Content-Type': undefined; };转换请求:任何; }' 不可分配给“RequestOptionsArgs”类型的参数。对象字面量只能指定已知属性,而“RequestOptionsArgs”类型中不存在“transformRequest”
【问题讨论】:
标签: angular typescript file-upload http-headers multipartform-data