之前没咋接触过文件上传,以为只能传文件流一个参数,工头让我找到拦截器文件,把其他参数也放进 file.append 方法,代码如下:
// 文件上传接口,使用文件流请求
const file = new FormData();
for (const [key, value] of Object.entries(cfg.data)) {
file.append(key, value);
}
req.data = file;
req.headers['Content-Type'] = 'multipart/form-data';
cfg.data = {
file: data.file, // 上传的文件
projectId: this.projectId,
templateType: this.paymentMoneyType === 'UNIFORM ' ? '0' : '1',
paymentType: 'EDU',
}
网友评论