Static images for blocks 404ing

default discord avatar
sam6466
2 months ago
5

I have some local images I want to use for the

imageURL

key for my blocks.



I have had them set like

/media/block-images/{{blockName}}.png

which was working, but now isn't.



I don't believe it's related to Payload, more likely a config issue. But I was wondering if there were some detailed docs on serving static assets in general?

  • default discord avatar
    notchr
    2 months ago

    Good morning @sam6466 I think this is the most relevant documentation:

    https://payloadcms.com/docs/upload/overview#enabling-uploads


    Although, when serving content, depending on how your server is setup, you may need to create an nginx entry for the content



    Happy to expand on that, but let me know if that part of the doc is helpful

  • default discord avatar
    sam6466
    2 months ago

    Thanks. I’ll see if I need to setup an entry in the server.js. The weird part is this was working before and looking at the logs for the server and payload config, nothing changed. I’ll investigate further 😊

  • default discord avatar
    notchr
    2 months ago

    Hmmm



    @sam6466 Do the assets show as 404? Can you access the image url directly and do they show?



    Some other thoughts: Are the access controls for the upload collection set to allow public view?

  • default discord avatar
    sam6466
    2 months ago

    No, the images 404. They are not part of an image collection as I want them to be served statically as the preview images for blocks, and they’re part of the repo. Before I was able to access them at /media/block-images/…



    I had to add

    app.use('/media', express.static(path.join(__dirname, 'media')));

    to the server.js



    Will try and dig into how this was working before

  • default discord avatar
    notchr
    2 months ago

    @sam6466 Let me know if you run into any more issues, happy to help troubleshoot

Open the post
Continue the discussion in Discord
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.