Commit ac46214
authored
fix: follow redirects when fetching uploaded files for MIME type detection (#16708)
## Summary
- When using S3 (or any storage adapter) with `signedDownloads` enabled,
the `staticHandler` returns a `302` redirect to a pre-signed URL.
Payload's `addDataAndFileToRequest` utility calls this handler
internally to fetch back the just-uploaded file for MIME type detection,
but Node.js `fetch` does not automatically follow redirects on a
`Response` object returned from an internal handler call — resulting in
an empty `ArrayBuffer` and a `DataView.getUint16()` bounds error.
- The existing guard in the S3 `staticHandler` (`if (signedDownloads &&
!clientUploadContext)`) was meant to skip the redirect for internal
upload processing, but fires anyway when `clientUploadContext` is
`undefined` (i.e. when no upload context is configured for the
collection).
- Added redirect-following between receiving the handler response and
consuming its body: if the response is a 3xx redirect,
`addDataAndFileToRequest` now follows the `Location` header to retrieve
the actual file bytes before processing.1 parent f1861c1 commit ac46214
1 file changed
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
105 | 112 | | |
106 | 113 | | |
107 | 114 | | |
| |||
0 commit comments