2017-04-09 36 views
0

每次嘗試將數據發佈到API時都出現錯誤。 請求:POST文件multipart/form-data(JavaScript)時出錯

changeUserAvatar(authParam, file) { 
    let formData = new FormData(); 
    //file is actually new FileReader.readAsDataURL(myId.files[0]); 
    formData.append('profile_image', file); 

    fetch(BASE_URL + 'profile-image', { 
    method: 'POST', 
    headers: { 
    'Content-Type': 'multipart/form-data', 
    'Authorization': authParam 
    }, 
    body: formData 
    }).then((response) => { 
    return response.json(); 
    }).then((response) => { 
    debugger; 
    }).catch((error) => { 
    console.error(error); 
    }); 
} 

錯誤:profile_image不能爲空(422)。

但它不是空白!

請求負載enter image description here

我該怎麼辦錯了嗎?

回答