I want to stream the object that is gotten from the aws sdk which is of type aws_smithy_types::byte_stream to actix web response which expects a futures::stream
Here is the get function:
pub async fn get(&self, object_name: &str) -> Option<ByteStream> {
let get_request = self
.client
.get_object()
.bucket(&self.bucket_name)
.key(object_name)
.send()
.await;
if get_request.is_ok() {
let result = get_request.unwrap();
debug!("{:?}", result);
info!("Got successfully {} from {}", object_name, self.bucket_name);
let bytes: ByteStream = result.body;
Some(bytes)
} else {
error!("{:?}", get_request.unwrap_err());
error!("Unable to get {} from {}.", object_name, self.bucket_name);
None
}
}```
and here is the place i want to return the stream directly to client
// Get the file content as a stream of bytes
if let Some(mut stream) = s3.get(&obj_id.to_string()).await {
// while let Ok(Some(bytes)) = stream.try_next().await {
// println!("{:?}", bytes);
// }
// HttpResponse::Ok().body("Stream")
}
I have tried many methods but cannot solve it.