我正在使用此代码将文件上传到Dwolla。因此,要上传文档/文件,我需要将其以多部分形式发送。
这是我的代码,
const multipartFormData = async fileLocation => {
let base64Data = "";
await image2base64(fileLocation) // you can also to use url
.then(response => {
base64Data = response;
});
var boundary = "----" + new Date().getTime();
var bodyString = [];
bodyString.push(
"--" + boundary,
'Content-Disposition: form-data; name="' +
"file" +
'";' +
'filename="' +
"my_file.jpg" +
'"',
"Content-Type: " + "image/jpeg",
"Content-Transfer-Encoding: base64",
"", //need /r/n twice here
base64Data.substring(23) //remove the data:image/jpeg;base64,
);
bodyString.push("--" + boundary + "--", "");
var content = bodyString.join("\r\n");
const reqBody = {
documentType: "other",
file: {
content: content,
headers: {
"Content-Type": "multipart/form-data; boundary=" + boundary,
"Content-Length": content.length
}
}
};
uploadDoc(reqBody);
};
但是,当我尝试上传它时,出现此错误:
{"status":415,"headers":{},"body":{"code":"UnsupportedRequestContentType","message":"Invalid request Content-Type. multipart/form-data."}}
任何人都可以帮助找到问题所在。