'Angular FormData cannot append my data like in React
I'm recording an audio file and sending it to a server using multipart/formdata. In React, my FormData is good, but not in Angular.
My React version works great, here it is :
let data = new FormData();
data.append("file", {
uri: uri,
name: "file.m4a",
type: "audio/m4a",
});
If I console.log this data, I get for example :
{"_parts":[["file",{"uri":"file:///data/user/0/com.app/cache/Audio/recording.m4a","name":"file.m4a","type":"audio/m4a"}]]}
Now, I need this for Angular version, but FormData are not defined the same, and I don't know how to correct this.
If I do the same for Angular, I have an error :
Argument of type '{ uri: string; name: string; type: string; }' is not assignable to parameter of type 'string | Blob'.
And if I console.log the data, I get nothing.
What is the correct version for appending my data for Angular, with these parameters ?
In Angular, the definition of FormData is :
declare var FormData: {
prototype: FormData;
new(form?: HTMLFormElement): FormData;
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
