我正在从文件中读取块中的字节,然后尝试上载每个块(这是字节缓冲区),当我使用Content type作为“ multipart / from-data”时,它给了我错误,即没有定义边界。如何定义我的代码的边界,摘要如下:
const fs = require('fs');
function getByteArray(filePath){
let fileData = fs.readFileSync(filePath);
return fileData;
}
url = "http://localhost:8080/upload"
uploading = function (file){
var fileBuffer = getByteArray(file)
var buffer = Buffer.from(fileBuffer);
var i,tempBuf
for (i=0;i< buffer.length; i+=(500)) {
tempBuf = buffer.slice(i,i+(500));
postRequest(url, tempBuf)
};
}
postRequest: function postRequest(url, byteBuffer) {
return new Promise(function(resolve, reject) {
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
resolve(xhr.responseText)
} else {
reject(xhr.status + "--" + xhr.responseText)
}
} else if (xhr.status != 200){
// console.log()
}else {
// console.log()
}
}
xhr.ontimeout = function () {
reject('timeout')
}
xhr.open("POST", url, true)
xhr.setRequestHeader("Content-Type","multipart/form-data");
xhr.send(byteBuffer);
})
}
,错误如下:
"result":null,"error":{"code":"request_parse_error","msg":"multipart: NextPart: EOF"}