How to send file through FormData()?


Hello I’m trying to send a file over to my api using FormData() in ionic 2. But it isnt working for me and I’m not sure what the correct way would be for this.
I currently create a:
let body = new FormData()
and then I try to append the file
body.append('key', file)

What I think is going wrong is that I dont have the correct file format and I’m only pointing towards the file locations. Anyone know how I could directly put the imagedata/file in there?

In Postman sending a ‘file’ with formdata works but I just cant seem to figure it out here.
I saw that there was a File plugin but I’m not sure how to use this to get what I want.

is it as simple as using a different Camera.DestinationType or do I have to do something else?

Thank you


What is this? Where does it come from?


Many seem to be using it, though I don’t know where it’s coming from:

p.s. FormData is documented here


FormData is used to send files and data in an api request in web applications. But in ionic that cannot be used. I have the same issue… Can anyone help


let body:FormData = new FormData();
body.append(‘userId’, ‘test’);
body.append(‘email’, ‘testmail’);

var options = { content: body };
return, options)
.map(res => res.json())

This is how we can use Form Data… To send file U have to pass the file array like this…

for(let fl of File){
body.append(‘file_’+count.toString(), fl);
… Hope it works


any new updates ? same problem with me :frowning: