Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Using CDN/Bucket URL Directly for Payload Uploads

default discord avatar
zed0547last year
19

Hey

@610189286809272348

,



Yes, I believe you're looking for this:

https://payloadcms.com/docs/upload/storage-adapters#payload-access-control

By setting

disablePayloadAccessControl: true

you bypass Payload

  • default discord avatar
    evisteronlast year

    Is it possible to configure that to use access control for draft content, but bypass for published content?



    Wait, can you have draft media content? Maybe that's not a thing

  • default discord avatar
    zed0547last year

    You

    can

    use drafts on media but it's kind of weird to think about tbh



    Why not make your collections where you

    consume

    the media draft instead?



    And handle access controls there

  • default discord avatar
    evisteronlast year

    I'm not sure I follow, but that's okay - this solution actually solves it for my case



    Do you mean like, rewrite the URL in the media propery on a page object for example?

  • default discord avatar
    zed0547last year

    You have posts that are drafts -> use access controls here


    You have media that you don't want to thread through payloads access controls -> use the property from above

  • default discord avatar
    evisteronlast year

    Yeah, that just exposes all the media - it's not highly discoverable, but if someone could guess the URL, they could get the media. In our case, that's fine.

  • default discord avatar
    zed0547last year

    Right, that's what disablePayloadAccessControl does

  • default discord avatar
    evisteronlast year

    Yeah this works - thanks!

  • default discord avatar
    zed0547last year

    My pleasure

  • default discord avatar
    evisteronlast year

    Actually, there's one more question - this setting will make it use the bucket URL - is there a way to rewrite that to point to another URL? In our set up, we have a bucket, behind a cloudfront CDN. I'd like it to use the cloudfront URL, not the bucket URL.

  • default discord avatar
    weetikveelmanlast year
  • default discord avatar
    evisteronlast year

    super, thanks



    Where do I add disablePayloadAccessControl: true - it's not clear from the docs

  • default discord avatar
    zed0547last year

    Payload build config upload options

  • default discord avatar
    evisteronlast year

    Like this?

  • default discord avatar
    zed0547last year

    Ah, no in the adapter config rather



    Iirc

  • default discord avatar
    evisteronlast year

    It seems to complain no matter where I put that:



    Am I using some out of date method to configure this maybe?

  • default discord avatar
    zed0547last year
    cloudStorage({
      collections: {
        'my-collection-slug': {
          adapter: theAdapterToUse,
          disablePayloadAccessControl: true
        },
      },
    }),
  • default discord avatar
    evisteronlast year

    Yeah, I'm not using cloudStorage - I guess I need to figure that out first

  • default discord avatar
    zed0547last year

    Try swapping out your collections.media for { ... } and put it in there

  • default discord avatar
    evisteronlast year

    hmm, that works



    so that can be a config object, good to know

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.