表单数据未附加文件对象

时间:2019-03-22 13:08:08

标签: angularjs form-data

在向文件对象添加表单数据时出现问题,将文件对象附加到表单数据之后,表单数据为空对象。请建议

scope.uploadDigitalSignature = function (form) {
if (scope.digitalFiles.length) {
scope.docDetails.aliasName = scope.docDetails.aliasName;
scope.docDetails.digipassword = scope.docDetails.digipassword;
scope.docDetails.certificate = scope.docDetails.certificate;

var file = scope.digitalFiles[0];
var formData = new FormData(this);
formData.append('file', file);
// FileUpload.upload(scope.digitalFiles,docId,function(success,blobData){
var config = {
headers: { 
'Content-Type': 'multipart/form-data',
}
}; 
var blobData = {
"file" : scope.docDetails.certificate
};
AdminService.uploadDigitalSignature(function(){
toastr.success('Signature uploaded successfully');
},docId,scope.docDetails.aliasName,scope.docDetails.digipassword ,blobData,config);
//}

//);
}
};

console log of file object and form data

1 个答案:

答案 0 :(得分:2)

FormData Object是一个奇异对象,其内容不可直接用于JavaScript。

要检索FormData对象的内容,请使用其.entries()方法:

var contents = Array.from(formData.entries());
console.log(contents);

有关更多信息,请参见MDN Web API Reference - FormData.entries()