diff --git a/src/builder/create_attachment.rs b/src/builder/create_attachment.rs index 32cacad827e..2ddc5d0bd4c 100644 --- a/src/builder/create_attachment.rs +++ b/src/builder/create_attachment.rs @@ -1,6 +1,7 @@ use std::borrow::Cow; use std::path::Path; +use bytes::Bytes; use serde::ser::{Serialize, SerializeSeq, Serializer}; use tokio::fs::File; use tokio::io::AsyncReadExt; @@ -21,15 +22,12 @@ use crate::model::id::AttachmentId; pub struct CreateAttachment<'a> { pub filename: Cow<'static, str>, pub description: Option>, - pub data: Cow<'static, [u8]>, + pub data: Bytes, } impl<'a> CreateAttachment<'a> { /// Builds an [`CreateAttachment`] from the raw attachment data. - pub fn bytes( - data: impl Into>, - filename: impl Into>, - ) -> Self { + pub fn bytes(data: impl Into, filename: impl Into>) -> Self { CreateAttachment { data: data.into(), filename: filename.into(), @@ -85,7 +83,7 @@ impl<'a> CreateAttachment<'a> { filename: impl Into>, ) -> Result { let response = http.client.get(url).send().await?; - let data = response.bytes().await?.to_vec(); + let data = response.bytes().await?; Ok(CreateAttachment::bytes(data, filename)) } diff --git a/src/http/multipart.rs b/src/http/multipart.rs index 81b32c9c605..58d2f4a77b6 100644 --- a/src/http/multipart.rs +++ b/src/http/multipart.rs @@ -7,7 +7,7 @@ use crate::internal::prelude::*; impl CreateAttachment<'_> { fn into_part(self) -> Result { - let mut part = Part::bytes(self.data); + let mut part = Part::stream(self.data); part = guess_mime_str(part, &self.filename)?; part = part.file_name(self.filename); Ok(part)