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, R>( upload_url: U, reader: R, ) -> Result<UploadSession, GraphFailure>
Sourcepub fn stream(
&mut self,
) -> Result<impl Stream<Item = Result<Response, GraphFailure>>, GraphFailure>
pub fn stream( &mut self, ) -> Result<impl Stream<Item = Result<Response, GraphFailure>>, GraphFailure>
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, ) -> Result<Receiver<Result<Response, Error>>, GraphFailure>
pub fn channel_timeout( &mut self, timeout: Duration, ) -> Result<Receiver<Result<Response, Error>>, GraphFailure>
pub fn channel_buffer_timeout( &mut self, buffer: usize, timeout: Duration, ) -> Result<Receiver<Result<Response, Error>>, GraphFailure>
Trait Implementations§
Source§impl AsyncIterator for UploadSession
impl AsyncIterator for UploadSession
type Item = Result<Response, GraphFailure>
fn next<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Option<<UploadSession as AsyncIterator>::Item>> + Send + 'async_trait>>where
'life0: 'async_trait,
UploadSession: 'async_trait,
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