From f867db20b85b24cf01a6080733ab563a9ce697b6 Mon Sep 17 00:00:00 2001 From: brian Date: Thu, 17 Aug 2023 15:48:24 +0800 Subject: [PATCH] fix: upload by buffer --- lib/index.ts | 5 ++++- package.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index 2663ca0..ee75134 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -54,6 +54,8 @@ export = { const cos = new COS(COSInitConfig); return { + upload, + uploadStream: upload, delete(file: File): Promise { @@ -114,6 +116,7 @@ export = { } function upload(file: File): Promise { + if (!file.stream && !file.buffer) return Promise.reject(new Error('Missing Readable Stream or Buffer')); const Key = getFileKey(file) return new Promise((resolve, reject) => { cos.putObject( @@ -122,7 +125,7 @@ export = { Bucket, Region, Key, - Body: file.stream, + Body: file.stream || file.buffer, ContentLength: kbytesToBytes(file.size), ContentType: file.mime, }, diff --git a/package.json b/package.json index cb98a39..b01b001 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "strapi-provider-upload-tencent-cloud-storage", - "version": "1.0.7", + "version": "1.0.8", "description": "A integration of Tencent Cloud COS as a file storage solution within Strapi.", "main": "dist/index.js", "directories": {