fix(storage-vercel-blob): client uploads with a prefix (#12559)
Fixes https://github.com/payloadcms/payload/issues/12544
This commit is contained in:
@@ -30,5 +30,7 @@ export const VercelBlobClientUploadHandler =
|
||||
if (addRandomSuffix) {
|
||||
updateFilename(result.url.replace(`${baseURL}/`, ''))
|
||||
}
|
||||
|
||||
return { prefix }
|
||||
},
|
||||
})
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 })
|
||||
|
||||
Reference in New Issue
Block a user