How to send file through FormData()?


#1

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


#2

What is this? Where does it come from?


#3

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




p.s. FormData is documented here


#4

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