I want to upload a .tar.gz file (>500mb) to a URL using javascript.
Here is my approach
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;
}
},
Using the above code I can upload smaller files but not able to upload larger files.
In case of larger files, the app crashes.
2
Answers
Are you using Chrome? Chrome seems to have a Blob limit of 500mb, restricting the request size to about 500mb. See this chromium issue You could try uploading using firefox, to see if the issue persists.
Check out this chunked uploading method: