#amazon-s3 #s3 #web #api-bindings #s3v4

s3-presign

A minimal library for generating presigned URLs for Amazon S3 compatible services

3 releases

0.0.3 Oct 18, 2024
0.0.2 Feb 2, 2023
0.0.1 Jan 15, 2023

#247 in Authentication

Download history 203/week @ 2024-07-31 352/week @ 2024-08-07 118/week @ 2024-08-14 189/week @ 2024-08-21 20/week @ 2024-08-28 25/week @ 2024-09-04 20/week @ 2024-09-11 27/week @ 2024-09-18 114/week @ 2024-09-25 61/week @ 2024-10-02 53/week @ 2024-10-09 188/week @ 2024-10-16 163/week @ 2024-10-23 40/week @ 2024-10-30 168/week @ 2024-11-06 235/week @ 2024-11-13

611 downloads per month

MIT/Apache

20KB
426 lines

s3-presign

Minimal library to get an S3 presign URL.

Usage

use s3_presign::{Credentials, Presigner};

let credentials = Credentials::new(
    "blah.....blah...",
    "blah.....xxxxxxx",
    None,
);

let bucket = "my-bucket";
let region = "us-east-1";

let mut presigner = Presigner::new(credentials, bucket, region);
// presigner.endpoint(endpoint);
let url = self.presigner.url_for_s3_url(path).unwrap();

let signed_url = self.sign_s3_request("HEAD", &url);

let signed_url = self.sign_s3_request("PUT", &url);
let signed_url = self.sign_s3_request("GET", &url);

S3-compatible APIs

If you want to use the presigner with a different service that exposes an S3-compatible API (like Cloudflare R2), you can do so by specifying a root when creating the Presigner/Bucket.

let root = "xxxxx.eu.r2.cloudflarestorage.com";

let bucketObj = Bucket::mew_with_root(bucket, root, root);
let mut preBucket = Presigner::from_bucket(credentials, bucketObj);
preBucket.use_path_style(); // Cloudflare R2 only works with Path-Style!!!

let mut presigner = Presigner::new_with_root(credentials, bucket, region, root);

⚠️ Cloudflare R2

The R2s S3-API requires path style! Therefore, you can not use the global convenience function. Instead you need to create a Presigner and call Presigner::use_path_style(&self) on it.

Dependencies

~3.5–5MB
~84K SLoC