Media upload does not save file in production

default discord avatar
xlukasfrana
last month
1 1

Hi,
I encountered an error when file is not written to the filesystem when it is uploaded. However, this happens only in production. In development, everything works. The config for media collection is pretty standard.

What's even more strange is that no error is encountered and the image is being correctly shown in the media list. I do not know from where, because it is not written do the disk. Maybe some cache?

Thanks for any help

import path from "path";
import type { CollectionConfig } from "payload/types";

export const Media: CollectionConfig = {
  slug: "media",
  upload: {
    staticDir: path.resolve(__dirname, "..", "..", "files", "media"),
  },
  fields: [
    {
      name: "name",
      type: "text",
    },
  ],
};
  • default discord avatar
    xlukasfrana
    last month

    Sorry, I have found the bug in the meanwhile. The problem was that in development, the media files were saved to /files/media, like shown in the example.

    However, when compiled to production, the project gets compiled to dist folder, so in the end, the Payload saves media files to /dist/files/media. Silly error, but took a while to spot it.

    Thanks!

  • discord user avatar
    denolfe
    Payload Team
    last month

    I encountered an error when file is not written to the filesystem when it is uploaded.

    What is the error exactly?

    1 reply
    default discord avatar
    xlukasfrana
    last month

    Sorry, I have found the bug in the meanwhile. The problem was that in development, the media files were saved to /files/media, like shown in the example.

    However, when compiled to production, the project gets compiled to dist folder, so in the end, the Payload saves media files to /dist/files/media. Silly error, but took a while to spot it.

    Thanks!

Open the post
Continue the discussion in GitHub
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.