From a56fa1f1883a3c308224a8cd36284aa662e2411d Mon Sep 17 00:00:00 2001 From: asonix Date: Fri, 21 Jul 2023 19:17:26 -0500 Subject: [PATCH] Add content-length --- src/store/object_store.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/store/object_store.rs b/src/store/object_store.rs index 4e4e512..1aaef1d 100644 --- a/src/store/object_store.rs +++ b/src/store/object_store.rs @@ -14,7 +14,7 @@ use actix_web::{ }; use base64::{prelude::BASE64_STANDARD, Engine}; use futures_util::{Stream, StreamExt, TryStreamExt}; -use reqwest::{header::RANGE, Response}; +use reqwest::{header::RANGE, Body, Response}; use reqwest_middleware::{ClientWithMiddleware, RequestBuilder}; use rusty_s3::{actions::S3Action, Bucket, BucketError, Credentials, UrlStyle}; use std::{pin::Pin, string::FromUtf8Error, time::Duration}; @@ -207,9 +207,11 @@ impl Store for ObjectStore { if first_chunk.len() < CHUNK_SIZE { drop(stream); - let (req, object_id) = self.put_object_request(content_type).await?; + let (req, object_id) = self + .put_object_request(first_chunk.len(), content_type) + .await?; let response = req - .body(first_chunk.into_bytes()) + .body(Body::wrap_stream(first_chunk)) .send() .await .map_err(ObjectError::from)?; @@ -266,7 +268,7 @@ impl Store for ObjectStore { &upload_id2, ) .await? - .body(buf.into_bytes()) + .body(Body::wrap_stream(buf)) .send() .await .map_err(ObjectError::from)?; @@ -337,7 +339,7 @@ impl Store for ObjectStore { bytes: Bytes, content_type: mime::Mime, ) -> Result { - let (req, object_id) = self.put_object_request(content_type).await?; + let (req, object_id) = self.put_object_request(bytes.len(), content_type).await?; let response = req.body(bytes).send().await.map_err(ObjectError::from)?; @@ -483,6 +485,7 @@ impl ObjectStore { async fn put_object_request( &self, + length: usize, content_type: mime::Mime, ) -> Result<(RequestBuilder, ObjectId), StoreError> { let path = self.next_file().await?; @@ -492,6 +495,9 @@ impl ObjectStore { action .headers_mut() .insert("content-type", content_type.as_ref()); + action + .headers_mut() + .insert("content-length", length.to_string()); Ok((self.build_request(action), ObjectId::from_string(path))) }