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

CloudFlare R2 (http) #318

Closed
1 task
juretopolak opened this issue Oct 11, 2023 · 7 comments
Closed
1 task

CloudFlare R2 (http) #318

juretopolak opened this issue Oct 11, 2023 · 7 comments

Comments

@juretopolak
Copy link

juretopolak commented Oct 11, 2023

Describe the feature

This is an experimental driver! This driver only works in a cloudflare worker environment and cannot be used in other runtime environments such as Node.js (r2-http driver is coming soon)

I would just like to ask if you have any approx. date when r2-http driver will be released? I would like to use CF R2 in the Node environment and I'm wondering if it is better to wait for a "native" nuxt/nitro/unstorage driver or the release is not close so it's better to go with another solution? 🙂

Thanks!

Additional information

  • Would you be willing to help implement this feature?

Tasks

Preview Give feedback
No tasks being tracked yet.
@pi0 pi0 added driver request enhancement New feature or request labels Oct 11, 2023
@pi0
Copy link
Member

pi0 commented Oct 11, 2023

Hi dear @juretopolak. Feel free to draft a PR if you are willing to help supporting this driver earlier 👍🏼

@juretopolak
Copy link
Author

Hi @pi0. I'm actually a TypeScript newbie, so I doubt my PR would be useful at all. 🙂 Maybe someday in the future... until then I'll keep learning and admiring the work you experts do. 👌

@cosbgn
Copy link

cosbgn commented Oct 16, 2023

Hi @juretopolak I had to deal with this recently, I found that the best way is to use aws4fetch which works on all environments, including workers.
You need something like this, inside for example /api/upload-file.js:

import { AwsClient } from 'aws4fetch'
const aws = new AwsClient({ accessKeyId, secretAccessKey })
// Then you can just send a PUT / GET / DELETE request
await aws.fetch(R2_BUCKET_URL, { body: buffer, method: 'PUT', ContentType: type })

It's super easy with aws4fetch - With native $fetch is more complex because you need to somehow generate the AWS Signature Version 4

@pi0
Copy link
Member

pi0 commented Oct 16, 2023

Really nice find. I certainly like to consider aws4fetch. There are small items (such as crypto polyfill to use uncrypto) we can either (temporarily) inline impl to make those or work with @mhart if you would like to make it happen!

@pi0 pi0 removed the enhancement New feature or request label May 1, 2024
@MickL
Copy link

MickL commented Dec 6, 2024

I guess R2 http is kinda rare because it is an extra overhead if you upload a file to your API (which is not hosted on a Cloudflare worker) and then send the file to Cloudflare by another "upload". If you use Cloudflare R2 it makes sense if your api also runs und Cloudflare so there is no extra transfer from your API to R2.

If you cant deploy to Cloudflare Workers, what you could also do is create an empty Nitro project and deploy it to Cloudflare Pages. Then use this one for file uploads directly from the client or with your api as a proxy.

Btw. since R2 has a S3 api, maybe also this one works?
https://github.com/profilecity/unstorage-s3-driver

@pi0 pi0 closed this as completed Dec 9, 2024
@pi0 pi0 reopened this Dec 11, 2024
@pi0
Copy link
Member

pi0 commented Dec 11, 2024

(sorry i mistakenly closed issue. r2 over HTTP driver is not supported yet)

@MickL MickL mentioned this issue Dec 11, 2024
12 tasks
@pi0
Copy link
Member

pi0 commented Dec 18, 2024

S3 supported landed in #361 which is also tested against r2 over HTTP. for now only mentioned in docs in the future we might make a dedicated driver leveraging more native addons of cloudflare r2 if needed.

@pi0 pi0 closed this as completed Dec 18, 2024
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

4 participants