How to send FormData() in ionic this.http.post()

#1

I am implementing file upload functionality in ionic using Http, But Its not working, Here is my code:
uploadFile(event) {
var file = document.getElementById(‘ImportInputField’);
var data = event.target.files;
let totaldocLength = event.target.files.length;
if(totaldocLength > 0){
for(var i = 0; i < totaldocLength; i++){
var filename = data[i].name;
this.uploadFileAPI(data[i], “”, filename);
}
}
}

uploadFileAPI(files,page,fileName){
//var folderId = “”;
//var dataGrid = “”;
var CabinetId = “2bc74202-a4bd-4ab6-b1d7-e749c675e47a”;
var formData = new FormData();
formData.append(“file”, files);
//var data = formData;
console.log(“data==”+ formData);
const httpOptions = {
headers: new HttpHeaders({
‘Content-Type’: ‘application/json’,
‘Authorization’: this.token }),
dataType: ‘json’,
//data: formData
};
this.http.post(this.apiUrl +’/files/upload?cabinetId=’+ CabinetId,
JSON.stringify(formData), httpOptions)
.subscribe(response => {
alert(“sucess”);
console.log(response);
},
err => {
console.log(err.error); console.log(err.name); console.log(err.message);console.log(err.status);
console.log("ERROR!: ", err);
});
}

It always goes to error section(Failed to load resource: the server responded with a status of 404 ()
main.js:485 ) even File full information are there. I am trying to print the console.log( formData);But It return me formdata. I can not see the file information from file data.
Please help me how we can add this form data in out http.post request.

#2

any updates … same problem with me :frowning: