这边我们需要const formData =new FormData()一个新对象,然后把组件中file的originFileObj放入,就可以把组件返回的文件转成(二进制)传到后端了
export const getFile = async (file) => {
const formData = new FormData()
formData.append('file_name', file.name)
formData.append('is_annex', true)
formData.append('title', '')
formData.append('content_type', file.type)
formData.append('file', file.originFileObj)
return request.post('xxxxxxxx', {
data: formData,
})
}
文章讲述了如何在JavaScript中使用`FormData`对象将组件中的`file.originFileObj`转换为二进制格式,并通过异步`request.post`方法上传到指定的后端接口。
1640

被折叠的 条评论
为什么被折叠?



