use multipart-upload

This commit is contained in:
fyears 2021-11-10 01:03:33 +08:00
parent a7e6bed071
commit 6757348ac9
2 changed files with 16 additions and 4 deletions

View File

@ -35,6 +35,7 @@
},
"dependencies": {
"@aws-sdk/client-s3": "^3.37.0",
"@aws-sdk/lib-storage": "^3.40.1",
"@aws-sdk/signature-v4-crt": "^3.37.0",
"acorn": "^8.5.0",
"aws-crt": "^1.10.1",

View File

@ -3,6 +3,7 @@ import { Readable } from "stream";
import { Vault } from "obsidian";
import { Upload } from "@aws-sdk/lib-storage";
import {
S3Client,
ListObjectsV2Command,
@ -115,14 +116,24 @@ export const uploadToRemote = async (
remoteContent = await encryptArrayBuffer(localContent, password);
}
const body = arrayBufferToBuffer(remoteContent);
await s3Client.send(
new PutObjectCommand({
const upload = new Upload({
client: s3Client,
queueSize: 20, // concurrency
partSize: 5242880, // minimal 5MB by default
leavePartsOnError: false,
params: {
Bucket: s3Config.s3BucketName,
Key: uploadFile,
Body: body,
ContentType: contentType,
})
);
},
});
upload.on("httpUploadProgress", (progress) => {
// console.log(progress);
});
await upload.done();
return await getRemoteMeta(s3Client, s3Config, uploadFile);
}
};