-
Hello, I've been using the the aws-sdk-rust library to upload files without the presigned URL. But recently I needed to change how I was uploading files to S3. So I have a service that will generate a presigned url for me and use a http redirect after its been generated to make the proceeding call the s3 for PUT or GETs. But, I am not sure if I am understanding the documentation incorrectly or I might have missed something. But it looks like once a presigned url has been generated I have to use a different library to make the HTTP call and stream the contents to the body or chunk the file if its greater than 5mb. Similar to this example, from an issue listed here: #423. My current attempt is looking like this, but I can't seem to stream the data from a large file into the body and have it upload to S3. let tokio_file = tokio::fs::File::open(metadata.temp_file_path).await?;
let stream = FramedRead::new(tokio_file, BytesCodec::new());
let body = Body::wrap_stream(stream);
reqwest::Client::new()
.put("my-service-to-gen-me-presigned-url-and-redirect-me.com")
.body(body)
.send()
.await?; But I was trying to see if there was a way to just pass in the presigned url into the sdk and use it to the method prior to having to generate a presigned url. So instead of giving it bucket/key I could just give it the presigned url and then send the body. let aws_config = load_from_env().await;
let client = Client::new(&aws_config);
let byte_stream = ByteStream::read_from()
.path(temp_file)
.build()
.await?;
match client.put_object().bucket(bucket_name).key(&s3_file_path).body(byte_stream).send().await {
Ok(..) => {
return Ok(());
}
Err(err) => {
let sleep_in_ms = u64::pow(2, num_retries) * 100;
sleep(Duration::from_millis(sleep_in_ms)).await;
num_retries += 1;
if num_retries > max_retries {
return Err(err.into());
}
}
} Most, if not all, examples I've found interacting with a presigned url use something like |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
yes—you need to use a different library if you want to use a presigned URL. The Rust SDK doesn't contain a publicly accessible HTTP client or any prebuilt code for working with presigned URLs once generated from the SDK. If you're uploading a large file, you'll need to presign the multipart upload request, then operate on those URLs. An example of using multipart upload is here: https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/rust_dev_preview/s3/src/bin/s3-multipart-upload.rs |
Beta Was this translation helpful? Give feedback.
yes—you need to use a different library if you want to use a presigned URL. The Rust SDK doesn't contain a publicly accessible HTTP client or any prebuilt code for working with presigned URLs once generated from the SDK.
If you're uploading a large file, you'll need to presign the multipart upload request, then operate on those URLs.
An example of using multipart upload is here: https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/rust_dev_preview/s3/src/bin/s3-multipart-upload.rs