美文网首页
上传文件踩的坑记录一下

上传文件踩的坑记录一下

作者: 前端技师胡帅博 | 来源:发表于2019-10-19 11:43 被阅读0次

之前没咋接触过文件上传,以为只能传文件流一个参数,工头让我找到拦截器文件,把其他参数也放进 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',
                }

相关文章

网友评论

      本文标题:上传文件踩的坑记录一下

      本文链接:https://www.haomeiwen.com/subject/uzbgmctx.html