From a30b1ae540eb4019ffc089f589c581b06e5c0cf0 Mon Sep 17 00:00:00 2001 From: asonix Date: Fri, 21 Jul 2023 18:54:29 -0500 Subject: [PATCH] Aggregate bytes list into single bytes for object storage This is a workaround for reqwest overriding the content-length header --- Cargo.lock | 2 +- Cargo.toml | 2 +- pict-rs.nix | 2 +- src/bytes_stream.rs | 4 ++++ src/store/object_store.rs | 6 +++--- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4c473c7..9bf5068 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1621,7 +1621,7 @@ dependencies = [ [[package]] name = "pict-rs" -version = "0.4.2-rc.1" +version = "0.4.2-rc.2" dependencies = [ "actix-form-data", "actix-rt", diff --git a/Cargo.toml b/Cargo.toml index 5009c96..ef49915 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pict-rs" description = "A simple image hosting service" -version = "0.4.2-rc.1" +version = "0.4.2-rc.2" authors = ["asonix "] license = "AGPL-3.0" readme = "README.md" diff --git a/pict-rs.nix b/pict-rs.nix index cc60f71..976cb25 100644 --- a/pict-rs.nix +++ b/pict-rs.nix @@ -12,7 +12,7 @@ rustPlatform.buildRustPackage { pname = "pict-rs"; - version = "0.4.2-rc.1"; + version = "0.4.2-rc.2"; src = ./.; cargoLock = { diff --git a/src/bytes_stream.rs b/src/bytes_stream.rs index 5ca7c6c..b3182a2 100644 --- a/src/bytes_stream.rs +++ b/src/bytes_stream.rs @@ -84,4 +84,8 @@ impl futures_util::Stream for BytesStream { fn poll_next(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { Poll::Ready(self.get_mut().inner.pop_front().map(Ok)) } + + fn size_hint(&self) -> (usize, Option) { + (self.inner.len(), Some(self.inner.len())) + } } diff --git a/src/store/object_store.rs b/src/store/object_store.rs index 6cba941..4e4e512 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, Body, Response}; +use reqwest::{header::RANGE, Response}; use reqwest_middleware::{ClientWithMiddleware, RequestBuilder}; use rusty_s3::{actions::S3Action, Bucket, BucketError, Credentials, UrlStyle}; use std::{pin::Pin, string::FromUtf8Error, time::Duration}; @@ -209,7 +209,7 @@ impl Store for ObjectStore { drop(stream); let (req, object_id) = self.put_object_request(content_type).await?; let response = req - .body(Body::wrap_stream(first_chunk)) + .body(first_chunk.into_bytes()) .send() .await .map_err(ObjectError::from)?; @@ -266,7 +266,7 @@ impl Store for ObjectStore { &upload_id2, ) .await? - .body(Body::wrap_stream(buf)) + .body(buf.into_bytes()) .send() .await .map_err(ObjectError::from)?;