pub struct UploadSession { /* private fields */ }
Implementations§
Source§impl UploadSession
impl UploadSession
pub fn empty(url: Url) -> UploadSession
pub fn url(&self) -> &Url
pub fn status(&self) -> RequestBuilder
pub fn cancel(&self) -> RequestBuilder
pub fn from_reader<U: AsRef<str>, R: Read>( upload_url: U, reader: R, ) -> GraphResult<UploadSession>
Sourcepub fn stream(
&mut self,
) -> GraphResult<impl Stream<Item = GraphResult<Response>> + '_>
pub fn stream( &mut self, ) -> GraphResult<impl Stream<Item = GraphResult<Response>> + '_>
Stream upload session responses.
Each stream.next().await returns a Option<GraphResult<reqwest::Response>>
.
No pinning is required. The stream is pinned before being returned to the caller.
§Example
ⓘ
use graph_rs_sdk::*;
use futures::stream::StreamExt;
use std::fs::OpenOptions;
static ACCESS_TOKEN: &str = "ACCESS_TOKEN";
// Path to upload file to in OneDrive.
static ONEDRIVE_PATH: &str = ":/file.txt:";
static LOCAL_FILE_PATH: &str = "./file.txt";
let client = Graph::new("ACCESS_TOKEN");
let response = client
.me()
.drive()
.item_by_path(ONEDRIVE_PATH)
.create_upload_session(&serde_json::json!({
"@microsoft.graph.conflictBehavior": Some("fail".to_string())
}))
.send()
.await?;
assert!(response.status().is_success());
let mut file = OpenOptions::new()
.read(true)
.open(LOCAL_FILE_PATH)?;
let mut upload_session = response.into_upload_session(file).await?;
let mut stream = upload_session.stream()?;
while let Some(result) = stream.next().await {
match result {
Ok(response) => {
println!("{response:#?}");
let body: serde_json::Value = response.json().await?;
println!("{body:#?}");
}
Err(err) => panic!("Error on upload session {err:#?}")
}
}
pub fn channel(&mut self) -> GraphResult<Receiver<Result<Response>>>
pub fn channel_timeout( &mut self, timeout: Duration, ) -> GraphResult<Receiver<Result<Response>>>
pub fn channel_buffer_timeout( &mut self, buffer: usize, timeout: Duration, ) -> GraphResult<Receiver<Result<Response>>>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for UploadSession
impl !RefUnwindSafe for UploadSession
impl Send for UploadSession
impl Sync for UploadSession
impl Unpin for UploadSession
impl !UnwindSafe for UploadSession
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more