I'm using rusoto S3 to create a JSON string and upload this string to an S3 bucket. I can create the string, but rusoto's S3 PutObjectRequest
requires a StreamingBody
and I'm not sure how I can create a StreamingBody
from a string or whether this is actually necessary.
extern crate json;
extern crate rusoto_core;
extern crate rusoto_s3;
extern crate futures;
use rusoto_core::Region;
use rusoto_s3::{S3, S3Client, PutObjectRequest};
fn main() {
let mut paths = Vec::new();
paths.push(1);
let s3_client = S3Client::new(Region::UsEast1);
println!("{}", json::stringify(paths));
s3_client.put_object(PutObjectRequest {
bucket: String::from("bucket"),
key: "@types.json".to_string(),
body: Some(json::stringify(paths)),
acl: Some("public-read".to_string()),
..Default::default()
}).sync().expect("could not upload");
}
The error I get is
error[E0308]: mismatched types
--> src/main.rs:16:20
|
16 | body: Some(json::stringify(paths)),
| ^^^^^^^^^^^^^^^^^^^^^^ expected struct `rusoto_core::ByteStream`, found struct `std::string::String`
|
= note: expected type `rusoto_core::ByteStream`
found type `std::string::String`
I'm not sure how to give this a ByteStream
... ByteStream::new(json::stringify(paths))
does not work and gives me a different error.
How can I upload a string?