Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions packages/plugin-cloud-storage/src/utilities/getIncomingFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@ export function getIncomingFiles({

let files: File[] = []

if (file && data.filename && data.mimeType) {
const effectiveFilename = data.filename ?? file?.name
const effectiveMimeType = data.mimeType ?? file?.mimetype

if (file && effectiveFilename && effectiveMimeType) {
const mainFile: File = {
buffer: file.data,
clientUploadContext: file.clientUploadContext,
filename: data.filename,
filename: effectiveFilename,
filesize: file.size,
mimeType: data.mimeType,
mimeType: effectiveMimeType,
tempFilePath: file.tempFilePath,
}

files = [mainFile]

if (data?.sizes) {
Object.entries(data.sizes).forEach(([key, resizedFileData]) => {
if (payloadUploadSizes?.[key] && resizedFileData.mimeType) {
const sizes = data?.sizes ?? payloadUploadSizes

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix for the main file case. I think there may still be a gap for resized images when sizes is also projected out because req.payloadUploadSizes only has the resized buffers, while the resized file metadata still comes from data.sizes. So with this fallback, resizedFileData can be a Buffer, which means resizedFileData?.mimeType is undefined and the resized variants still won’t be uploaded.

Could you, please, add a regression test for an image upload with configured sizes where the selected doc omits sizes along with filename / mimeType?

if (sizes) {
Object.entries(sizes).forEach(([key, resizedFileData]) => {
if (payloadUploadSizes?.[key] && resizedFileData?.mimeType) {
files = files.concat([
{
buffer: payloadUploadSizes[key],
Expand Down
Loading