Crates.io | s3-presign |
lib.rs | s3-presign |
version | |
source | src |
created_at | 2023-01-15 07:34:28.015964 |
updated_at | 2024-10-18 04:21:21.183134 |
description | A minimal library for generating presigned URLs for Amazon S3 compatible services |
homepage | https://github.com/andelf/s3-presign |
repository | https://github.com/andelf/s3-presign |
max_upload_size | |
id | 759285 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Minimal library to get an S3 presign URL.
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);
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 callPresigner::use_path_style(&self)
on it.