0

Im completely new to rust, but learning. I am attempting to take a multipart upload using actix_web and actix_multipart and upload it to aws s3 using rusoto_s3. From my basic undersntaing basically i have a stream of one type that i need to convert into a ByteStream which is what put_object PutObjectRequest { body } is requiring.

I presume i need to use map on the field to convert it from one type to another, but I'm a little lost.

E.g Something along these lines?

pub fn save_file_s3(field: Field, s3_client: &S3Client) {
    let bucket = env::var("S3_BUCKET").expect("S3 bucket must be set.");

    let item = field.map();

    s3_client.put_object(PutObjectRequest {
        bucket: bucket,
        body: item,        
        ..Default::default()
    }).into_stream();
}

Thanks for the help!

Deep
  • 2,988
  • 4
  • 34
  • 44
  • You can check [this gist](https://gist.github.com/zrzka/8d7a31d39206f31e9cbafc6456546b60). I quickly hacked something you can start with. **WARNING** Not properly tested, finished, polished ... It just works for couple of files I tried. – zrzka Aug 21 '19 at 13:43
  • Also I'm going to cast close vote. Reason - this is too broad question and `field.map()` says that you didn't spend much time researching / trying to implement it. Try a bit more, ask specific questions, ... – zrzka Aug 21 '19 at 13:47
  • Hi thanks, sorry I didnt put all my attempts, it's just the compiler complained so I knew it was wrong. Thanks for the gist, I'll take a look, seems like it's not as straightforward as I would have imagined. – Deep Aug 21 '19 at 21:41
  • Copy & paste the gist somewhere and use `cargo fmt`. Seems that GitHub broke formatting. – zrzka Aug 22 '19 at 06:50
  • This implementation is kind of imperfect hybrid. Questions to ask yourself (& to improve your question): Should upload request wait for S3 upload or return as soon as the whole file is received (async vs sync)? Is the file size limited (S3 put object vs S3 multipart upload)? How many files it will handle? What should happen when S3 upload fails? Retry? How many times? Inform you somehow? Should the uploaded file be saved to a temporary folder and then there will be some uploader which will receive path of a file to upload via a channel (async, request returns, S3 upload queued)? – zrzka Aug 22 '19 at 06:59

0 Answers0