Ashtav
Ashtav

Reputation: 2966

null when append data to FormData()

I have data structure like this on vue

data: {
   name: 'Lorem',
   status: 'Active',
   username: 'user-01',
   password: '12345'
},

then I append to FormData() because I want to send blob data (image) to the server, like this

let formData = new FormData(this.data); // my data
formData.append('photo', this.blob);

I use axios, the image are sent but data is not, when I display formData.entries() on console, the result is

photo, [object File]

How I can solve this? thanks

Upvotes: 0

Views: 365

Answers (1)

Pratik Patel
Pratik Patel

Reputation: 6978

Rembermer FormData has no Constructor that takes JSON data as an argument.

Try this

let formData = new FormData();
for ( var key in data ) {
    formData.append(key, data[key]);
}
formData.append('photo', this.blob);
for (var pair of formData2.entries()) {
    console.log(pair[0]+ ', ' + pair[1]); 
}

Upvotes: 1

Related Questions