#Intermittent BAD Request for Upload Collection in Payload Cloud

1 messages · Page 1 of 1 (latest)

dusk pagoda
#

I have a simple file upload collection

export const KioskImages: CollectionConfig = {
  slug: 'kiosk-images',
  access: {
    read: () => true,
    create: canCreateImage(),
  },
  fields: [],
  upload: true,
}

I am able to Upload to it using the rest API locally with no issues with simple code to upload, where file is coming from a file input:

  const addImage = async (file: File): Promise<PayloadKioskImage | null> => {
    try {
      if (file.size === 0) {
        throw new Error('Attempted to upload empty file')
      }

      const formData = new FormData()
      formData.append('file', file)

      const options: RequestInit = {
        method: 'POST',
        body: formData
      }

      const { data, error } = await fetch(`api/kiosk-images`, options).json()
      if (error.value) throw error.value
      if (data.value.doc) return data.value.doc
    } catch (e) {
      console.log(e)
      toast({
        title: `Error adding image`
      })
    }
    return null
  }

When I try on my production instance on Payload Cloud I get intermittent 400 Bad Request Errors. On the same image. Sometimes it works, sometimes it doesnt and there is no idication as to why.

400 Bad Request
{"errors":[{"message":"There was a problem while uploading the file."}]}

The cloud logs show the following.

2025-03-20T21:30:19]
[21:30:19] ERROR: Empty file
[2025-03-20T21:30:19]
err: {
[2025-03-20T21:30:19]
"type": "Error",
[2025-03-20T21:30:19]
"message": "Empty file",
[2025-03-20T21:30:19]
"stack":
[2025-03-20T21:30:19]
Error: Empty file
[2025-03-20T21:30:19]
at u (/workspace/packages/apps/cms/.next/server/chunks/3077.js:27:35748)
[2025-03-20T21:30:19]
}
[2025-03-20T21:30:19]
[21:30:19] ERROR: There was a problem while uploading the file.

But the file is definetly not empty and it works randomly sometimes. And always works locally.

naive thorn
#

Hi. Did you manage to solve this? I have the same exact issue...

brave fox
#

I would double check what you are actually recieving in your addImage function as the file - are you sure this is a file? Also, check your create access controls because it doesn't seem like you are passing credentials through to the post request here.

naive thorn
#

Hey @brave fox, thanks for the attention on this issue. I am using the admin UI. So if I keep uploading the same image over and over again it will sometimes fail and sometimes work. At first I thought it's something with bulk functionality, but I have reproduced with single image. I also thought it might be some config issue or file size, but the fact that the same exact image intermittently works/fail is an indicator that the underlying upload might be faulty. I am using the Cloud hosting from Payload, which comes with the image storage pre-configured

full coyote
#

Hey @brave fox I am also getting this issue when uploading images through the admin. It seems to only happen when using Payload Cloud; everything works fine locally. My setup is based on the website starter with few changes to the Media collection.

brave fox
#

IIRC someone mentioned that the devs were aware of some issues around this and were working out a fix, so it should be resolved soon

#

Unfortunately I don't have more insight there

full coyote
#

Okay, thank you 🙂

full coyote
#

@brave fox where did you see this information? I've been trying to track down some Github issue or Discord thread with some information about this issue but I haven't been able to. It seems like a pretty important issue... We're currently looking at ditching Payload Cloud and hosting ourselves since we cannot get this to work in production.

brave fox
#

It was either in another community-help thread where a user jumped in and mentioned reaching out to support via email, or in general chat