durch / rust-s3

Rust library for interfacing with S3 API compatible services
MIT License
498 stars 195 forks source link

Cloudflare R2 put_object_stream fails every time with SignatureDoesNotMatch error #355

Open Sharpiro opened 11 months ago

Sharpiro commented 11 months ago

Describe the bug When using the library with Cloudflare R2, the put_object_stream function fails every time with an 8MB file of all 0s (and any other large file I tired). It gives the following error:

Error: Got HTTP 403 with content '<?xml version="1.0" encoding="UTF-8"?><Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your secret access key and signing method. </Message></Error>'

To Reproduce

use s3::{creds::Credentials, Bucket, Region};
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let account_id = std::env::var("S3_ID")?;
    let access_key_id = std::env::var("S3_ACCESS_KEY_ID")?;
    let secret_access_key = std::env::var("S3_SECRET_ACCESS_KEY")?;
    let credentials = Credentials::new(
        Some(&access_key_id),
        Some(&secret_access_key),
        None,
        None,
        None,
    )?;
    let bucket =
        Bucket::new("multipart-testing", Region::R2 { account_id }, credentials)?.with_path_style();

    // empty_file_8_mb = `dd if=/dev/zero of=empty_file_8_mb bs=1 count=8388608`
    let mut file = tokio::fs::File::open("empty_file_8_mb").await?;
    let result = bucket
        .put_object_stream(&mut file, "empty_file_8_mb")
        .await?;

    dbg!(&result);

    Ok(())
}

Expected behavior I expect it to upload the file with no errors.

Environment

Additional Context

I tried various combinations of nightly, the 0.34.0-beta3 beta, using slashes, not using slashes, always the same result.

I also tried using put_multipart_chunk manually from an existing multipart upload to ensure it was not a concurrency issue and I still get the same error.

Uploading the entire object from memory with put_object works fine.

Test file created with dd if=/dev/zero of=empty_file_8_mb bs=1 count=8388608