javascript - 如何将文件内容类型更改为多部分/表单数据
问题描述
我有这种文件数据
{uid: "vc-upload-1577940007821-10", lastModified: 1552282096988, lastModifiedDate: Mon Mar 11 2019 13:28:16 GMT+0800 (Malaysia Time), name: "Backup Call.pdf", size: 30973, …}
这是从 ant design vue upload 收到的。我不知道多部分/表单数据是什么样的。我需要将此作为请求发送到 post API。但 API 要求我以多部分形式发送。如何将此数据更改为多部分形式?是否有任何引用、功能或任何方式可以将这些数据更改为多部分格式?
这是我的结构的样子:
<a-upload-dragger
name="File"
:multiple="true"
action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
@change="handleChange"
:beforeUpload="checkFormat"
:showUploadList="false"
></a-upload-dragger>
这是我使用的功能:
checkFormat(file) {
const isPDF = file.type === 'application/pdf';
if (!isPDF) {
this.$message.error('You can only upload PDF file!');
}
return isPDF;
},
handleChange(info) {
if (info.file.status === 'done') {
this.uploadFile(info.file);
this.$message.success(`${info.file.name} file upload successfully.`);
} else if (info.file.status === 'error') {
this.$message.error(`${info.file.name} file upload failed.`);
}
},
我想创建一个函数,将格式更改为函数中的多theuploadFile()
部分
解决方案
推荐阅读
- firebase - 未从 Firebase 存储中检索到下载 URL
- javascript - promise.all 以并行方式执行承诺,但单线程 JS 如何在后台工作
- tcl - 删除等号后的部分字符串
- reporting-services - 锁定 SQL Server Reporting Services 2016
- javascript - 将 PHP 变量传递给 AngularJS 变量
- javascript - 无符号右移零位是什么意思?
- python - 如何安装 discord.py 重写?
- internet-explorer - 配置要在 Internet Explorer 上查看的 SAP Fiori 应用程序
- sql-server-2008 - 在组合多行的值时包含自定义逻辑
- regex - 什么是有效 Git 标签的正则表达式?