When uploading files to a
Media
collection, the
url
displays as the absolute URL in local dev, but only shows the relative path in prod (deployed to Payload Cloud).
For example, when querying a
User
that has an
avatar
field with relationship to
Media
:
Local:
{
"id": "645d8e5115c5b421de227a98",
...
"avatar": {
"id": "645e035d6435660db51755de",
...
"url": "http://localhost:4000/media/avatar.jpg"
},
}
Prod:
{
"id": "645d8e5115c5b421de227a98",
...
"avatar": {
"id": "645e035d6435660db51755de",
...
"url": "/media/avatar.jpg"
},
}
Is this intended or is it a bug?
Are both running the same version of Payload? There was a recent small feature added in the latest version that could have introduced a bug. 1f 1.7.5 works but 1.8.2 doesn't, I would point to it being a new bug.
What does your upload collection config look like? Are you using an env var for staticURL that could be different between environments?
My collection config looks like this:
import type { CollectionConfig, Field } from 'payload/types'
const alt: Field = {
name: 'alt',
label: 'Alt Text',
type: 'text',
required: true
}
export const Media: CollectionConfig = {
slug: 'media',
access: {
read: (): boolean => true // Everyone can read Media
},
upload: {
staticURL: '/media',
staticDir: 'media',
mimeTypes: ['image/*', 'video/*'],
adminThumbnail: 'card',
imageSizes: [
{
name: 'card',
width: 640,
height: 480
},
{
name: 'feature',
width: 1024,
height: 576
}
]
},
fields: [alt]
}
export default Media
Using version Payload 1.8.2
not using any env vars outside of what Payload Cloud configures (I also just installed the Payload Cloud plugin to see if that would fix it, but no luck)
I think the difference may be ENV vars
Does your config contain serverURL property?
my config does have
serverURL
specified. Do I need to add the
PAYLOAD_PUBLIC_SERVER_URL
env var to the cloud config as well? I'd assumed Payload automatically sets that.
oh that was it - I had to set
PAYLOAD_PUBLIC_SERVER_URL
in Payload Could. Thank you!!
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.