Skip to content

feat: re-use adapter logic for upload updates #13069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

wesdimiceli
Copy link
Contributor

Context:

I'm running Payload in a private subnet with a cookie-based auth gateway (which federates to an SSO provider).

Problem:

In a deployed setting, updating the focus point or crop area for an image and re-saving it results in a generic 500.

I tracked it down to this code section:

file = await getExternalFile({

The codepath re-uses the http machinery to fetch the image from wherever it may be stored. The issue here is that upload URLs are based on server hostname, which is correct for users/browsers, but with my setup Payload cannot send requests to itself that way.

Architecturally, I'm guessing that the fetch call is to accommodate the side loading feature where you can paste the direct asset URL. However, I'm wondering if it's unnecessary to invoke the whole http flow to re-fetch an asset that was already uploaded.

Changes:

With the above in mind, I refactored getFile.ts to split up the logic such that it's reusable internally without making a full request. This enables payload to use the configured upload adapters directly, using the same code path as the regular REST endpoint.

Then, if we're doing an update operation, we can go directly to the cloud storage plugin instead of making a round trip to the API endpoint.

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.

1 participant