I can send a file to the server using axios and the FormData api, like that :
persist(avatar){
let data = new FormData();
data.append('avatar', avatar);
axios.post(`/api/users/${this.user.name}/avatar`, data)
.then(() => flash('Avatar uploaded!'));
}
The avatar param, passed to persist(), is a file object from a form input of type "file".
I can then grab the file on the server side.
Is it possible to do it without using FormData ? That is, to simulate the FormData work ? Basically, I'm trying to understand the extra work done by the FormData api. Maybe it's not possible using axios, and I should do that with plain XMLHttpRequest.
Of course, simply sending the file object won't work :
axios.post(`/api/users/${this.user.name}/avatar`, {avatar: avatar})
On the server side, the avatar object will be empty. I can send metadata like avatar.name, but not the whole object.