From d91c815406943908d12fffc3218a5616445a8659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Mon, 16 Sep 2024 12:12:09 +0200 Subject: [PATCH] fix(blob): respect `addRandomSuffix` with remote access (#287) --- playground/server/api/browser/capture.ts | 4 +++- src/runtime/blob/server/api/_hub/blob/[...pathname].put.ts | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/playground/server/api/browser/capture.ts b/playground/server/api/browser/capture.ts index 6233d6ae..f7b08fdf 100644 --- a/playground/server/api/browser/capture.ts +++ b/playground/server/api/browser/capture.ts @@ -31,7 +31,9 @@ export default eventHandler(async (event) => { // Upload the screenshot to the Blob storage const filename = `screenshots/${btoa(url + theme)}.jpg` - await hubBlob().put(filename, screenshot) + await hubBlob().put(filename, screenshot, { + addRandomSuffix: false + }) await page.close() setHeader(event, 'content-type', 'image/jpeg') diff --git a/src/runtime/blob/server/api/_hub/blob/[...pathname].put.ts b/src/runtime/blob/server/api/_hub/blob/[...pathname].put.ts index 3aeef042..e467313c 100644 --- a/src/runtime/blob/server/api/_hub/blob/[...pathname].put.ts +++ b/src/runtime/blob/server/api/_hub/blob/[...pathname].put.ts @@ -31,6 +31,8 @@ export default eventHandler(async (event) => { options.customMetadata = {} } } + // sanitize addRandomSuffix which is a boolean + options.addRandomSuffix = options.addRandomSuffix === 'true' const stream = getRequestWebStream(event)! const body = await streamToArrayBuffer(stream, Number(contentLength))