Repository navigation
fix(storage-vercel-blob): upload processed client files from temp file - #18388
Conversation
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
5e43f72 to
b51d26d
Compare
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
b51d26d to
0567c26
Compare
0567c26 to
4e4902a
Compare
a5757b0 to
eec4418
Compare
JarrodMFlesch
left a comment
There was a problem hiding this comment.
One small readability suggestion in the R2 upload helper.
7641ad3 to
07a694b
Compare
07a694b to
4c7bc90
Compare
4c7bc90 to
6799c72
Compare
6799c72 to
6739873
Compare
…abeled client uploads (#18913) Stacked on #18388. Review and merge #18388 first. ## Summary Direct client uploads with a crop or a wrong MIME type do not store the processed file. A crop returns a 500 error. A file with a wrong MIME type keeps the original bytes in storage, but the document describes the processed file. ## How - The storage plugin runs a second update to save adapter metadata. That update now runs without `uploadEdits`. Before, it applied the crop again and tried to download the file, which failed. `main` already does this. - When Payload corrects the MIME type, `req.file` now points to the corrected copy of the file. Before, only the copy was marked as processed, so the storage plugin skipped the upload. - When a crop and `resizeOptions` are both set, the temp file now gets the cropped and resized bytes. Before, it got only the cropped bytes. ## Tests The resized client-upload test now also covers a cropped upload and an upload with a wrong MIME type. The test collection has an image size, so each case also covers crops together with `imageSizes`. Each case checks that the stored sizes of the main file and the image size are equal to their `filesize` values on the document. Both new cases failed before this change. ## Related work - Stack: #18388 → this PR → #18920 → #18921 - Issue: #18333 --------- Co-authored-by: Jarrod Flesch <[email protected]>
…RandomSuffix (#18920) Stacked on #18913. Review and merge #18388 and #18913 first. This PR does not depend on their changes. It is in the stack because #18921 changes the same adapter code. Fixes #9589. ## Summary With `addRandomSuffix: true`, Vercel Blob uploads the main file and each image size in parallel. Every upload wrote its suffixed name to the same `data.filename`. As a result, the document filename could point to an image size, and no image size got its suffixed name. Every image-size URL returned 404. Now each upload writes its suffixed name only to its own entry: an image size updates `sizes.<name>.filename`, and the main file updates `filename`. ## How - After each upload finishes, the adapter finds the image size whose filename matches the uploaded file. If no size matches, the file is the main file. - Two image sizes with the same dimensions get the same filename. The adapter finds the entry after the upload, so a size that an earlier upload renamed does not match again. Each size gets its own entry. - `storage-uploadthing` already uses this pattern for its per-file keys. - `plugin-cloud-storage` does not change. ## Tests - A unit test checks that the main file and an image size each update only their own filename. - A unit test uploads two image sizes with the same filename in parallel. It checks that each size gets its own suffixed filename. This test failed before this change. - An integration test uploads an image with one image size and `addRandomSuffix: true`. It checks that every filename on the document has an object in storage, and that the main object size is equal to the document `filesize`. This test failed on every run before this change. ## Related work - Stack: #18388 → #18913 → this PR → #18921 - The bug started in #5928, the first version of the storage packages. - Not in scope: #18384 (the create response has a `url` without the suffix) and #18804 (focal point with a new filename). --------- Co-authored-by: Jarrod Flesch <[email protected]>
…ploads with addRandomSuffix (#18921) Stacked on #18913. Review and merge #18388 and #18913 first. ## Summary With `addRandomSuffix: true`, a processed client upload was saved again under a new name with a suffix. The original file from the browser stayed in storage, and nothing used it. Now the processed file replaces the original file, and the document keeps the original filename. ## How - The server already saves the temp-file path of a client upload in `req.context` for cleanup. The adapter turns off `addRandomSuffix` when the file's `tempFilePath` is the same as that saved path. - The client cannot set this value, because the server sets both paths. - The check does not use `_objectKey`, so legacy overwrite receipts without `_objectKey` are covered too. - `payload` now exports `CLIENT_UPLOAD_TEMP_FILE_PATH_CONTEXT_KEY`, so the adapter does not copy the key string. ## Related work - Stack: #18388 → #18913 → this PR - Reported in a comment on #18333 and in the #18387 review. - #18920 fixes a separate `addRandomSuffix` bug with image sizes. Both PRs add `packages/storage-vercel-blob/src/adapter.spec.ts`, so the second one to merge needs a rebase.
…orage (#19010) Follow-up to #18388 for #18333. If Payload processed a direct-client upload, UploadThing could store a zero-byte file. The document still reported the processed file size. The adapter now uploads from the temporary file that holds the processed bytes, the same as Vercel Blob, GCS, and R2 after #18388. - For client uploads, Payload keeps the file on disk and does not load it into memory. After processing, the new bytes are in the temporary file and `file.buffer` is empty. - When `tempFilePath` is present, the UploadThing adapter reads the bytes from that file.
|
🚀 This is included in version v3.92.1 |
Summary
Fixes #18333, together with #18913. If Payload processed a direct-client upload, Vercel Blob, GCS, and R2 could store a zero-byte object. The document still reported the processed file size. These adapters now upload from the temporary file that holds the processed bytes. On 3.x, a crop with Vercel Blob first fails with a 500 error, so the crop case from the issue also needs #18913.
What
file.datais empty.tempFilePathis present, the Vercel Blob, GCS, and R2 adapters read the bytes from that file. S3 and Azure already do this.fsonly when it needs the temporary file, becausefsis not always available in Workers.