Search code examples
angularjsform-data

form data is not appending file object


I have a problem in appending file object with form data,after appending file object to form data,form data is empty object.Please suggest

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


Solution

  • A FormData Object is an exotic object whose contents is not directly available to JavaScript.

    To retrieve the contents of a FormData object, use its .entries() method:

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

    For more information, see MDN Web API Reference - FormData.entries()