官方文档如下:
To send the data as a
multipart/formdatayou need to pass a formData instance as a payload. Setting theContent-Typeheader is not required as Axios guesses it based on the payload type.
翻译出来就是:
要以 multipart/formdata 格式发送数据,需要将 formData 实例作为有效载荷传递。不需要设置 Content-Type 标头,因为 Axios 会根据有效载荷类型进行猜测。
但是目前在 1.4 版本使用时,未进行设置,进行文件上传操作,发现它并没有传递文件流。
而在 0.27 版本是可以自动进行转换的。
所以,遇到未进行转换时,请自行设置:
headers: {
'Content-Type': 'multipart/form-data',
},