Skip to content

Conversation

@jefferyto
Copy link
Contributor

What?

Fixes generateFileData using getExternalFile (external fetch) instead of getFileByPath (local file read) when getting file details/content for a Payload upload file when serverURL is set.

Why?

Currently, generateFileData checks if the file URL starts with a "/" to decide if the file is a file uploaded to Payload. The file URL will start with "/" when serverURL is not set. When serverURL is set the file URL starts with the serverURL value instead of "/", and so generateFileData treats the file as an external file.

How?

Instead of checking if the file URL starts with "/", compare the file URL to what a Payload file URL would be for the given filename.

Fixes #14945

@jefferyto jefferyto force-pushed the fix-local-file-edits-with-serverURL branch from 4b05dcf to 6e91ae6 Compare December 17, 2025 02:11
@jefferyto
Copy link
Contributor Author

I found another place where the code blindly tests the URL without considering serverURL:

if (!url.startsWith('http')) {
// URL points to the same server - we can send any cookies safely to our server.
trimAuthCookies = false
const baseUrl = req.headers.get('origin') || `${req.protocol}://${req.headers.get('host')}`
fileURL = `${baseUrl}${url}`
}

If serverURL is set, then the URL will start with "http", which leads to auth cookies being omitted from the request. (A custom externalFileHeaderFilter function would be the workaround for this case.)

Not sure if this should be addressed in this PR.

@DanRibbens
Copy link
Contributor

I thought this was all handled by #14869. @JarrodMFlesch can you verify if this is still an issue or we can close it?

@JarrodMFlesch
Copy link
Contributor

It was actually fully resolved in a later PR #14967

I can check if this is still an issue though.

@JarrodMFlesch JarrodMFlesch self-assigned this Dec 30, 2025
@jefferyto jefferyto force-pushed the fix-local-file-edits-with-serverURL branch from 6e91ae6 to 07d5838 Compare December 31, 2025 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants