[v3/plugin-cloud-storage] provide direct download links #6280
vixalien
started this conversation in
Feature Requests & Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently, when you use a cloud storage plugin like
gc2
and download a file, payload will fetch (stream) the requested file and then pass it to the user.https://github.com/payloadcms/payload/blob/a4ef359660a744cf39a7f539fbdf36c9eeb6a889/packages/storage-gcs/src/staticHandler.ts#L18C1-L36C9
This approach works correctly... sometimes. The issue comes when you host payload. Because payload is essentially downloading each file to the hosted instance before streaming it to the user, you end up with huge ingress/egress, and this can build up on platforms like Vercel.
A good solution would be to use Signed URLs. A signed URL is a temporary URL you can use to provide access to a file without making your whole bucket public. It essentially has all the authentication parameters in the URL itself, but it can be used for a (configurable) short time. When a user downloads a file from the API endpoint, payload could create a signed URL and redirect to it. In this scenario, Google Cloud will use their existing CDNs to serve the file to the user no matter where they are without compromising security.
A stopgap solution would be to simply use the 304 Not Modified header correctly, in the case the etag matches, so that browsers don't redownload the whole file again.
https://github.com/payloadcms/payload/blob/a4ef359660a744cf39a7f539fbdf36c9eeb6a889/packages/storage-gcs/src/staticHandler.ts#L38C1-L45C9
(cc @denolfe, we talked about this in the discord)
Beta Was this translation helpful? Give feedback.
All reactions