From ce74f1b238363056fd4247a82f2808e8a7bfa394 Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 18 Dec 2024 18:32:59 -0600 Subject: [PATCH] fix(storage-vercel-blob): fixes issue where files with spaces in their name would not be retrieved correctly (#10062) URI encodes filenames so that they're retrieved correctly from Vercel's blob storage. Sometimes spaces would cause problems only in certain file names --- packages/storage-vercel-blob/src/generateURL.ts | 2 +- packages/storage-vercel-blob/src/staticHandler.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/storage-vercel-blob/src/generateURL.ts b/packages/storage-vercel-blob/src/generateURL.ts index fcd3ae98f08..5a87e95570a 100644 --- a/packages/storage-vercel-blob/src/generateURL.ts +++ b/packages/storage-vercel-blob/src/generateURL.ts @@ -9,6 +9,6 @@ type GenerateUrlArgs = { export const getGenerateUrl = ({ baseUrl }: GenerateUrlArgs): GenerateURL => { return ({ filename, prefix = '' }) => { - return `${baseUrl}/${path.posix.join(prefix, filename)}` + return `${baseUrl}/${path.posix.join(prefix, encodeURIComponent(filename))}` } } diff --git a/packages/storage-vercel-blob/src/staticHandler.ts b/packages/storage-vercel-blob/src/staticHandler.ts index 107a887804e..aa2743fd7c5 100644 --- a/packages/storage-vercel-blob/src/staticHandler.ts +++ b/packages/storage-vercel-blob/src/staticHandler.ts @@ -18,7 +18,7 @@ export const getStaticHandler = ( return async (req, { params: { filename } }) => { try { const prefix = await getFilePrefix({ collection, filename, req }) - const fileKey = path.posix.join(prefix, filename) + const fileKey = path.posix.join(prefix, encodeURIComponent(filename)) const fileUrl = `${baseUrl}/${fileKey}` const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')