angular - 如何发送多部分/表单数据文件?
问题描述
我在 html 中有这个:
选择文件 handleFileInput(files: FileList) {
const headers = new Headers({ 'Content-Type': 'multipart/form-data' });
var formData = new FormData();
formData.append("myFile", files.item[0]);
this.api.postWithoutEntity('/socialintegration/callback/attachment', { recipientId: this.selected.custSocId, file: formData }).subscribe();
this.upload = false;
}
但我得到了这个:当前请求不是多部分请求”
有什么建议吗?
解决方案
我不知道您的 this.api.postWithoutEntity 方法是如何工作的,但您没有使用 headers 变量。您必须根据要求传递您的标头
const headers = new Headers({ 'Content-Type': 'multipart/form-data' });
return this.http.post<any>(
"/socialintegration/callback/attachment",
{recipientId: this.selected.custSocId, file: formData},
headers
);
推荐阅读
- javascript - 内置显示“矩形”的 HTML 编辑器
- sql - MongoDB多次查找到同一个集合
- java - 如何解决片段中的 Viewpager 问题?
- c# - 从外部程序集加载时,IServiceCollection 无法解析类型
- mysql - MySQL 授予本地 db 用户权限以允许远程主机使用 ansible
- php - 逻辑和代码codeigniter如何将页面查看注册过程的会话数据作为临时会话使用
- python - 在将日期从 obj 转换为 datetime 数据类型时在 python 中使用 Pandas,我没有正确转换日期。为什么?
- c# - C# Thread.Sleep() _PC 之间执行的其他时间
- java - HTTPS 证书(几乎)每周都会失效
- ios - 如何在 GoogleMobileAds 8.0 (Admob iOS sdk) 中使用 GADInterstitialAd?