1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Mobile: Fixes #3601: Fix uploading resource files to S3 with RN (#4127)

When the mobile application tries to synchronize a note with attached
resource files, e.g. from the notebook "Welcome! (Mobile)", readFile()
is called to return a Buffer although that isn't implemented in
FsDriverRN.readFile(). This is changing the code to return base64
encoded content from react-native and turn it into a Buffer before the S3
putObject() API call is used to create the remote object.

Tested with AVD Android 10.0 target.

Signed-off-by: Jan Blunck <jblunck@users.noreply.github.com>
This commit is contained in:
Jan Blunck 2020-11-29 18:29:46 +01:00 committed by GitHub
parent f001d197a8
commit f965708ad3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@ const { basicDelta } = require('./file-api');
const { basename } = require('./path-utils'); const { basename } = require('./path-utils');
const shim = require('./shim').default; const shim = require('./shim').default;
const JoplinError = require('./JoplinError'); const JoplinError = require('./JoplinError');
const { Buffer } = require('buffer');
const S3_MAX_DELETES = 1000; const S3_MAX_DELETES = 1000;
@ -83,12 +84,14 @@ class FileApiDriverAmazonS3 {
async s3UploadFileFrom(path, key) { async s3UploadFileFrom(path, key) {
if (!shim.fsDriver().exists(path)) throw new Error('s3UploadFileFrom: file does not exist'); 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) => { return new Promise((resolve, reject) => {
this.api().upload({ this.api().putObject({
Bucket: this.s3_bucket_, Bucket: this.s3_bucket_,
Key: key, Key: key,
Body: body, Body: Buffer.from(body, 'base64'),
ContentLength: `${fileStat.size}`,
}, (err, response) => { }, (err, response) => {
if (err) reject(err); if (err) reject(err);
else resolve(response); else resolve(response);