fix(storage-vercel-blob): client uploads with a prefix (#12559)

Fixes https://github.com/payloadcms/payload/issues/12544
This commit is contained in:
Sasha
2025-05-26 22:42:25 +03:00
committed by GitHub
parent 1731dd7c36
commit b61ef13481
3 changed files with 6 additions and 4 deletions

View File

@@ -30,5 +30,7 @@ export const VercelBlobClientUploadHandler =
if (addRandomSuffix) {
updateFilename(result.url.replace(`${baseURL}/`, ''))
}
return { prefix }
},
})

View File

@@ -112,7 +112,8 @@ export const vercelBlobStorage: VercelBlobStoragePlugin =
extraClientHandlerProps: (collection) => ({
addRandomSuffix: !!optionsWithDefaults.addRandomSuffix,
baseURL: baseUrl,
prefix: (typeof collection === 'object' && collection.prefix) || '',
prefix:
(typeof collection === 'object' && collection.prefix && `${collection.prefix}/`) || '',
}),
serverHandler: getClientUploadRoute({
access:

View File

@@ -15,11 +15,10 @@ export const getStaticHandler = (
{ baseUrl, cacheControlMaxAge = 0, token }: StaticHandlerArgs,
collection: CollectionConfig,
): StaticHandler => {
return async (req, { params: { filename } }) => {
return async (req, { params: { clientUploadContext, filename } }) => {
try {
const prefix = await getFilePrefix({ collection, filename, req })
const prefix = await getFilePrefix({ clientUploadContext, collection, filename, req })
const fileKey = path.posix.join(prefix, encodeURIComponent(filename))
const fileUrl = `${baseUrl}/${fileKey}`
const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')
const blobMetadata = await head(fileUrl, { token })