From ccc8a660c5aba0756b32e25831b47d4dc2956f6a Mon Sep 17 00:00:00 2001 From: yanglbme Date: Wed, 5 Mar 2025 15:39:00 +0800 Subject: [PATCH] fix: upload images with Cloudflare r2 --- src/utils/file.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/utils/file.ts b/src/utils/file.ts index 8b8286f67..b5a031697 100644 --- a/src/utils/file.ts +++ b/src/utils/file.ts @@ -381,20 +381,19 @@ async function mpFileUpload(file: File) { // Cloudflare R2 File Upload // ----------------------------------------------------------------------- -async function r2Upload(file: File) { +async function r2Upload(content: string, file: File) { const { accountId, accessKey, secretKey, bucket, path, domain } = JSON.parse( localStorage.getItem(`r2Config`)!, ) const dir = path ? `${path}/` : `` const filename = dir + getDateFilename(file.name) const client = new S3Client({ region: `auto`, endpoint: `https://${accountId}.r2.cloudflarestorage.com`, credentials: { accessKeyId: accessKey, secretAccessKey: secretKey } }) - return new Promise((resolve, reject) => { const putObjectCommand = new PutObjectCommand({ Bucket: bucket, Key: filename, ContentType: file.type, - Body: file, + Body: content, }) client.send(putObjectCommand).then(() => { resolve(`${domain}/${filename}`) @@ -462,7 +461,7 @@ function fileUpload(content: string, file: File) { case `mp`: return mpFileUpload(file) case `r2`: - return r2Upload(file) + return r2Upload(content, file) case `formCustom`: return formCustomUpload(content, file) default: