我使用鲁本 S3创建JSON字符串并将该字符串上传到S3桶。我可以创建字符串,但是rusoto的S3 PutObjectRequest需要一个StreamingBody,我不知道如何从字符串创建StreamingBody,或者这是否真的是必要的。
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");
}我得到的错误是
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`我不知道如何给它一个ByteStream. ByteStream::new(json::stringify(paths))不工作,给我一个不同的错误。
我如何上传字符串?
发布于 2018-12-16 18:54:09
StreamingBody是一个类型别名:
type StreamingBody = ByteStream;ByteStream有多个构造函数,包括一个From
impl From<Vec<u8>> for ByteStream您可以使用String将Vec<u8>转换为String::into_bytes。合在一起:
fn example(s: String) -> rusoto_s3::StreamingBody {
s.into_bytes().into()
}https://stackoverflow.com/questions/53799059
复制相似问题