Skip to content
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

File Upload #216

Open
olzii opened this issue Jul 29, 2020 · 3 comments
Open

File Upload #216

olzii opened this issue Jul 29, 2020 · 3 comments

Comments

@olzii
Copy link

olzii commented Jul 29, 2020

Do anyone have plan to add file upload feature ?

@koistya
Copy link
Member

koistya commented Jul 29, 2020

Yep, it will be added soon. It would look like an API endpoint that generates upload URL (to Google Storage Bucket or Amazon S3). The client app would request that URL and upload file(s) directly to cloud storage using HTTP PUT request.

mutation {
  getUploadURL(filename: "hello-world.jpg", ...)
}
await fetch(uploadURL, { method: "PUT", body: file });

Each uploaded file needs to have a unique URL (e.g. by prefixing it with file ID) so it can be permanently cached at the CDN level. And then can be requested directly from google storage by client app(s). For example:

https://s.example.com/nv4fzx/hello-world.jpg

Where s.example.com is a CDN endpoint (CNAME) pointing to gs://s.example.com GCS bucket, and nv4fzx is a unique file ID.

Also, it can be complemented with yet another cloud function that can be used to transform uploaded images via URL parameters, similarly to Cloudinary:

https://i.example.com/w_80,h_60,c_fill/nv4fzx/hello-world.jpg

Files

References

https://googleapis.dev/nodejs/storage/latest/File.html#generateSignedPostPolicyV4
https://cloud.google.com/functions/docs/tutorials/imagemagick
https://zelark.github.io/nano-id-cc/

P.S.: Join our Discord channel to discuss this feature https://discord.com/invite/bSsv7XM

@phpb-com
Copy link

Any update on this? Thanks.

@koistya
Copy link
Member

koistya commented Jan 29, 2022

@phpb-com yes, there is api/src/mutations/getUploadURL.ts and api/src/mutations/saveUpload.ts on the API side. All you have to do on the client is to request "upload URL", send the file(s) via HTTP PUT to that URL, then send "uploaded file URL" to the saveUpload() API mutation (which copies the file over from a temporary upload bucket location to a permanent place based on the linked content type (user photo, blog post pictures, etc.). As was described here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants