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) {
|
if (addRandomSuffix) {
|
||||||
updateFilename(result.url.replace(`${baseURL}/`, ''))
|
updateFilename(result.url.replace(`${baseURL}/`, ''))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return { prefix }
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -112,7 +112,8 @@ export const vercelBlobStorage: VercelBlobStoragePlugin =
|
|||||||
extraClientHandlerProps: (collection) => ({
|
extraClientHandlerProps: (collection) => ({
|
||||||
addRandomSuffix: !!optionsWithDefaults.addRandomSuffix,
|
addRandomSuffix: !!optionsWithDefaults.addRandomSuffix,
|
||||||
baseURL: baseUrl,
|
baseURL: baseUrl,
|
||||||
prefix: (typeof collection === 'object' && collection.prefix) || '',
|
prefix:
|
||||||
|
(typeof collection === 'object' && collection.prefix && `${collection.prefix}/`) || '',
|
||||||
}),
|
}),
|
||||||
serverHandler: getClientUploadRoute({
|
serverHandler: getClientUploadRoute({
|
||||||
access:
|
access:
|
||||||
|
|||||||
@@ -15,11 +15,10 @@ export const getStaticHandler = (
|
|||||||
{ baseUrl, cacheControlMaxAge = 0, token }: StaticHandlerArgs,
|
{ baseUrl, cacheControlMaxAge = 0, token }: StaticHandlerArgs,
|
||||||
collection: CollectionConfig,
|
collection: CollectionConfig,
|
||||||
): StaticHandler => {
|
): StaticHandler => {
|
||||||
return async (req, { params: { filename } }) => {
|
return async (req, { params: { clientUploadContext, filename } }) => {
|
||||||
try {
|
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 fileKey = path.posix.join(prefix, encodeURIComponent(filename))
|
||||||
|
|
||||||
const fileUrl = `${baseUrl}/${fileKey}`
|
const fileUrl = `${baseUrl}/${fileKey}`
|
||||||
const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')
|
const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')
|
||||||
const blobMetadata = await head(fileUrl, { token })
|
const blobMetadata = await head(fileUrl, { token })
|
||||||
|
|||||||
Reference in New Issue
Block a user