Skip to content

fix: use local file read for local upload edits when serverURL is set - #14951

Closed
jefferyto wants to merge 1 commit into
payloadcms:mainfrom
jefferyto:fix-local-file-edits-with-serverURL
Closed

jefferyto wants to merge 1 commit into
payloadcms:mainfrom
jefferyto:fix-local-file-edits-with-serverURL

Conversation

@jefferyto

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@DanRibbens

Copy link
Copy Markdown
Contributor

Since this was closed by #15089 I am guessing we can close it.

Can you please confirm @jefferyto?

@jefferyto

Copy link
Copy Markdown
Contributor Author

I retested #14945 with v3.71.1 and the issue was fixed - thanks.

@jefferyto jefferyto closed this Jan 14, 2026
@jefferyto
jefferyto deleted the fix-local-file-edits-with-serverURL branch January 14, 2026 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot edit image when serverURL is set

3 participants