Repository navigation
Cannot add custom prefix to uploads with S3 and ClientUploads #15532
Replies: 3 comments
|
Please add a reproduction in order for us to be able to investigate. Depending on the quality of reproduction steps, this issue may be closed if no reproduction is provided. Why was this issue marked with the
|
|
Hi @cstamati, sorry for the delay here! This behavior is due to the timing of client uploads vs hooks. When If you want to continue with this approach, you can clean up the original upload by deleting it in a hook that runs after the operation completes, for example: import { S3Client, DeleteObjectCommand } from '@aws-sdk/client-s3'
export const afterOperation = async ({ operation, result }) => {
if (operation !== 'create') return
await new S3Client({ region: process.env.AWS_REGION }).send(
new DeleteObjectCommand({
Bucket: process.env.S3_BUCKET!,
Key: `textures/${result.filename}`,
})
)
}This works, but it’s not ideal and adds extra work. There’s currently no supported way to have dynamic per-document upload paths with Converting this to a feature request since it requires new functionality rather than a bug fix. |
Uh oh!
There was an error while loading. Please reload this page.
Describe the Bug
Hello,
In my current setup I would like to organize my S3 and separate it by projects, here is an example:
To achieve this I enabled clientUploads (deploying on Vercel) and I added a hook on my "textures" collection that has already a default prefix in the payload config called "textures".
When I upload a texture in my S3 the file is uploaded 2 times in:
How can I achieve this?
Link to the code that reproduces this issue
(cannot provide repository since it needs S3 to reproduce)
Reproduction Steps
Which area(s) are affected? (Select all that apply)
plugin: other
Environment Info
All reactions