fix(file-s3): preserve directory structure from filename in object key#16030
fix(file-s3): preserve directory structure from filename in object key#16030adem-loghmari wants to merge 1 commit into
Conversation
The S3 file provider parsed the incoming filename but only used `parsedFilename.name` and `parsedFilename.ext`, so any directory portion (e.g. "vendor_123/logo.png") was dropped from the generated object key, flattening it to "logo-<ulid>.png". Preserve `parsedFilename.dir` when present so a filename such as "vendor_123/logo.png" yields "vendor_123/logo-<ulid>.png", while filenames without a directory are unaffected. Applied to both `upload()` and `getUploadStream()`. Fixes medusajs#16008 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: a5f269b The changes in this PR will be included in the next version bump. This PR includes changesets to release 80 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thanks for the contribution! Initial automated review looks good. Small, focused fix for accepted issue #16008 (type: bug / good first issue). Preserves directory structure from the supplied filename in the S3 object key, applied symmetrically to upload() and getUploadStream(); no-directory case is unchanged. PR template complete, changeset included, and unit tests cover both the directory and no-directory cases. Note for maintainers: the object key now includes caller-supplied directory segments — this is contained within the config prefix (S3 keys are literal, so '..' does not traverse), and only affects file-s3. Minor cosmetic edge: an absolute-path filen Triggered by: new PR opened |
What
Preserve any directory structure supplied in the filename when the S3 file provider generates an object key.
Closes #16008
Why
The provider parsed the incoming filename with
path.parsebut only usedparsedFilename.nameandparsedFilename.ext, dropping the directory portion. A filename likevendor_123/logo.pngwas flattened tologo-<ulid>.png, losing the caller-supplied structure.How
Prepend
parsedFilename.dir(with a trailing/) to the object key when present. Filenames without a directory are unaffected. Applied to bothupload()andgetUploadStream(), which shared the same logic.Example:
vendor_123/logo.pnglogo-<ulid>.pngvendor_123/logo-<ulid>.pnglogo.pnglogo-<ulid>.pnglogo-<ulid>.png(unchanged)Tests
Added unit tests covering directory preservation for both
upload()andgetUploadStream(), plus the no-directory case.