From 369b39e848440e94b63cc43093f0f85e887a1e76 Mon Sep 17 00:00:00 2001 From: fyears Date: Tue, 19 Oct 2021 00:38:20 +0800 Subject: [PATCH] fix binary file --- main.ts | 8 ++++++-- package.json | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/main.ts b/main.ts index 4fae71a..1f1be3e 100644 --- a/main.ts +++ b/main.ts @@ -1,5 +1,7 @@ import * as path from "path"; import * as fs from "fs"; +import { Buffer } from "buffer"; +import * as mime from 'mime-types'; import { App, Modal, @@ -86,7 +88,7 @@ export default class SaveRemotePlugin extends Plugin { } else { // file console.log(`file ${fileOrFolder.path}`); - const strContent = await this.app.vault.adapter.read( + const arrContent = await this.app.vault.adapter.readBinary( fileOrFolder.path ); new Notice(`file ${fileOrFolder.path}`); @@ -94,11 +96,13 @@ export default class SaveRemotePlugin extends Plugin { new PutObjectCommand({ Bucket: this.settings.s3BucketName, Key: `${fileOrFolder.path}`, - Body: strContent, + Body: Buffer.from(arrContent), + ContentType: mime.contentType(`${fileOrFolder.path}`) || undefined }) ); } } + new Notice('All upload finished!') } catch (err) { console.log("Error", err); new Notice(`${err}`); diff --git a/package.json b/package.json index 67e04dc..1876e32 100644 --- a/package.json +++ b/package.json @@ -38,11 +38,13 @@ }, "dependencies": { "@aws-sdk/client-s3": "^3.37.0", + "@types/mime-types": "^2.1.1", "codemirror": "^5.63.1", + "mime-types": "^2.1.33", + "obsidian": "^0.12.0", "rimraf": "^3.0.2", "webdav": "^4.7.0", - "webdav-fs": "^4.0.0", - "obsidian": "^0.12.0" + "webdav-fs": "^4.0.0" }, "@parcel/transformer-js": { "inlineFS": false,