Skip to content

Commit 454d0d3

Browse files
authored
fix(storage-r2): respect data.prefix in handleUpload path construction (#14485)
### What? Aligns the `storage-r2` adapter’s prefix handling with `storage-s3`. Previously, `storage-r2` always used the static prefix value from the adapter config, ignoring any dynamic `data.prefix` set via hooks (e.g., in `beforeOperation`). ### Why? In multi-tenant setups or other dynamic upload scenarios, developers may set a custom `req.data.prefix` to determine where files should be stored (e.g., under `<tenant>/<filename>`). This behavior worked correctly with the S3 adapter but was ignored by the R2 adapter, leading to inconsistent upload paths. ### How? Updated `handleUpload.ts` in the R2 adapter to respect `data.prefix` when present, falling back to the configured prefix otherwise. Fixes #14483
1 parent dff3d1b commit 454d0d3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/storage-r2/src/handleUpload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const getHandleUpload = ({ bucket, prefix = '' }: Args): HandleUpload =>
1515
return async ({ data, file }) => {
1616
// Read more: https://github.com/cloudflare/workers-sdk/issues/6047#issuecomment-2691217843
1717
const buffer = process.env.NODE_ENV === 'development' ? new Blob([file.buffer]) : file.buffer
18-
await bucket.put(path.posix.join(prefix, file.filename), buffer, {
18+
await bucket.put(path.posix.join(data.prefix || prefix, file.filename), buffer, {
1919
httpMetadata: { contentType: file.mimeType },
2020
})
2121

0 commit comments

Comments
 (0)