0

I'm working with Vue and using axios to send request. With POST method i have a request body with many data, everything work fine except when i try to send a file with it. In the chrome dev tool i could see that the field that suppose to have a file(blob object) in it turn out to be an empty object. I have try everthing with content-header and everything but it just wont work

axios({
    method : 'post',
    url : 'http://localhost:1323/restricted/Profile',
    headers: {
        'Content-Type': `multipart/form-data;`,
    },
    data : {
        name: this.name,
        pass: this.pass,
        email: this.email,
        fullname : this.fullname,
        isadmin : this.isAdmin,
        bdate : new Date(this.birthDate),
        startworkday : new Date(this.workDate),
        gender : this.gender,
        address : this.address,
        hometown : this.hometown,
        gradschool : this.gradschool,
        phonenum : this.phonenum,
        cv : this.cv,
        nominator : this.nominator,
        salary : this.salary,     
    },
})
.then((respone) => {
    console.log(respone.data);
});
julianstark999
  • 3,450
  • 1
  • 27
  • 41
Tuấn Lê
  • 176
  • 10
  • what happens if you `console.log(response.data.name)` inside `.then((response) = { ... })`? – DVN-Anakin Jun 15 '20 at 11:07
  • https://stackoverflow.com/questions/43013858/how-to-post-a-file-from-a-form-with-axios – RST Jun 15 '20 at 12:18
  • @RST when using formdata, the file field actually not send as an empty object anymore but rather like this : "(binary)". I don't think it work because the backend using golang with []byte still throw it out as an empty object. Beside that formdata make a lot of problem like : it can send object whereas if i do it the way before, the object got send without problem. I just can't see why axios make it this way – Tuấn Lê Jun 16 '20 at 04:09

0 Answers0