Skip to content

Commit b61ef13

Browse files
authored
fix(storage-vercel-blob): client uploads with a prefix (#12559)
Fixes #12544
1 parent 1731dd7 commit b61ef13

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

packages/storage-vercel-blob/src/client/VercelBlobClientUploadHandler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ export const VercelBlobClientUploadHandler =
3030
if (addRandomSuffix) {
3131
updateFilename(result.url.replace(`${baseURL}/`, ''))
3232
}
33+
34+
return { prefix }
3335
},
3436
})

packages/storage-vercel-blob/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ export const vercelBlobStorage: VercelBlobStoragePlugin =
112112
extraClientHandlerProps: (collection) => ({
113113
addRandomSuffix: !!optionsWithDefaults.addRandomSuffix,
114114
baseURL: baseUrl,
115-
prefix: (typeof collection === 'object' && collection.prefix) || '',
115+
prefix:
116+
(typeof collection === 'object' && collection.prefix && `${collection.prefix}/`) || '',
116117
}),
117118
serverHandler: getClientUploadRoute({
118119
access:

packages/storage-vercel-blob/src/staticHandler.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ export const getStaticHandler = (
1515
{ baseUrl, cacheControlMaxAge = 0, token }: StaticHandlerArgs,
1616
collection: CollectionConfig,
1717
): StaticHandler => {
18-
return async (req, { params: { filename } }) => {
18+
return async (req, { params: { clientUploadContext, filename } }) => {
1919
try {
20-
const prefix = await getFilePrefix({ collection, filename, req })
20+
const prefix = await getFilePrefix({ clientUploadContext, collection, filename, req })
2121
const fileKey = path.posix.join(prefix, encodeURIComponent(filename))
22-
2322
const fileUrl = `${baseUrl}/${fileKey}`
2423
const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')
2524
const blobMetadata = await head(fileUrl, { token })

0 commit comments

Comments
 (0)