首页 > 解决方案 > 如何将文件内容类型更改为多部分/表单数据

问题描述

我有这种文件数据

{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()部分

标签: javascriptvue.jsmultipartform-datamultipartantd

解决方案


推荐阅读