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.
I am doing this uploading thing from the client side only. By selecting a file by user we can upload. Is there any workaround so we can upload by giving the file path?