Skip to content

Instantly share code, notes, and snippets.

@semlinker
Last active August 7, 2022 02:19
Show Gist options
  • Save semlinker/4c04368541146a8083c9fd6a138227d1 to your computer and use it in GitHub Desktop.
Save semlinker/4c04368541146a8083c9fd6a138227d1 to your computer and use it in GitHub Desktop.
Concurrent Upload of Large Files in JavaScript
async function uploadFile() {
if (!uploadFileEle.files.length) return;
const file = uploadFileEle.files[0];
const fileMd5 = await calcFileMD5(file); // Calculate the MD5 of the file
const fileStatus = await checkFileExist(
// Check if the file already exists
"/exists",
file.name,
fileMd5
);
if (fileStatus.data && fileStatus.data.isExists) {
alert("File has been uploaded");
return;
} else {
await upload({
url: "/single",
file,
fileMd5,
fileSize: file.size,
chunkSize: 1 * 1024 * 1024,
chunkIds: fileStatus.data.chunkIds,
poolLimit: 3,
});
}
const fileData = await concatFiles("/concatFiles", file.name, fileMd5);
const {
data: {
data: { url },
},
} = fileData;
alert(`Uploaded file url is: ${url}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment