diff --git a/packages/lib/file-api-driver-amazon-s3.js b/packages/lib/file-api-driver-amazon-s3.js index 6e202db26..ddb187b4b 100644 --- a/packages/lib/file-api-driver-amazon-s3.js +++ b/packages/lib/file-api-driver-amazon-s3.js @@ -2,6 +2,7 @@ const { basicDelta } = require('./file-api'); const { basename } = require('./path-utils'); const shim = require('./shim').default; const JoplinError = require('./JoplinError'); +const { Buffer } = require('buffer'); const S3_MAX_DELETES = 1000; @@ -83,12 +84,14 @@ class FileApiDriverAmazonS3 { async s3UploadFileFrom(path, key) { if (!shim.fsDriver().exists(path)) throw new Error('s3UploadFileFrom: file does not exist'); - const body = await shim.fsDriver().readFile(path, 'Buffer'); + const body = await shim.fsDriver().readFile(path, 'base64'); + const fileStat = await shim.fsDriver().stat(path); return new Promise((resolve, reject) => { - this.api().upload({ + this.api().putObject({ Bucket: this.s3_bucket_, Key: key, - Body: body, + Body: Buffer.from(body, 'base64'), + ContentLength: `${fileStat.size}`, }, (err, response) => { if (err) reject(err); else resolve(response);