Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/olizilla/r2-signed-url

Test out signed urls for Cloudflare's R2
https://github.com/olizilla/r2-signed-url

Last synced: 9 days ago
JSON representation

Test out signed urls for Cloudflare's R2

Awesome Lists containing this project

README

        

# R2 signed URL test

Test out creating a signed url for Cloudflare's R2 that allows the user to upload a specific file with a given sha256 checksum, using the aws-sdk.

Pass the file to the script and it provides the upload URL as a curl command to try it out.

Heavily based on https://developers.cloudflare.com/r2/examples/aws-sdk-js-v3/

## Getting started

With:
- node v16 installed, install the deps (`npm i`)
- crate an R2 Bucket on cloudflare and some credentials
- create your `.env` file from `.env.tpl`, paste in the bucket name and credentials and and run the index.js

```bash
# pass a file you want to create an upload URL for
❯ node index.js olizilla.car
sha fhJ6TnbgLSToSkB936l5tzlhL/PuWCN+ggwrxpUr5ik=
curl -X PUT "https://..r2.cloudflarestorage.com/olizilla.car?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=309e401cdaab457aa9cfc6746e981134%2F20221005%2Fauto%2Fs3%2Faws4_request&X-Amz-Date=20221005T112921Z&X-Amz-Expires=3600&X-Amz-Signature=7725ba8b3e3e76deb8e14dda2975452c10ab3f5d824b01dee913984299b683d8&X-Amz-SignedHeaders=host&x-amz-checksum-sha256=fhJ6TnbgLSToSkB936l5tzlhL%2FPuWCN%2BggwrxpUr5ik%3D&x-id=PutObject" -F "[email protected]"
```

You can then copypasta and run that curl command in the same dir to upload the file to R2 usin the signed URL magic.

O!