diff --git a/package.json b/package.json index bc8170c..ee76b89 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/s3.ts b/src/s3.ts index 488f6d3..14151be 100644 --- a/src/s3.ts +++ b/src/s3.ts @@ -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); } };