我想使用 javascript 将 .tar.gz 文件(>500mb)上传到 URL。
这是我的方法
async uploadMapFile(url, FilePath, mapType) {
try {
let body = await _fs.promises.readFile(FilePath);
let contentType =
mapType === "navi" ? "application/zip" : "application/tar+gzip";
const { data } = await axios.put(url, body, {
headers: {
"Access-Control-Allow-Origin": process.env.APP_ORIGIN,
"Content-Type": contentType,
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Credentials": "true"
}
});
console.log("After uploading file", data, mapType);
//Removing the uploaded folder
await this.afterFileUpload(mapType);
this.store.mapUploadFlag = false;
} catch (error) {
console.log(error);
this.store.mapUploadFailed = true;
}
},
使用上面的代码我可以上传较小的文件,但无法上传较大的文件。 如果文件较大,应用程序会崩溃。
Chrome 似乎有 500mb 的 Blob 限制,将请求大小限制在 500mb 左右。请参阅此铬问题