mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-11-20 11:21:14 +00:00
Add content-length
This commit is contained in:
parent
a30b1ae540
commit
a56fa1f188
1 changed files with 11 additions and 5 deletions
|
@ -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<Self::Identifier, StoreError> {
|
||||
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)))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue