pub async fn upload(&self, url: &str, path: &str, _file: File) -> Result<()> {
        debug!("reading file content in bytes. file={:?}", path);
        let buffer = std::fs::read(path)?;

        let (status, message): (UploadStatus, Option<String>) =
            match self.http_client.put(url).body(buffer).send().await {
                Ok(res) if res.status() == 200 => (UploadStatus::Success, None),
                Ok(res) => {
                    error!("Server responded with status code {}", res.status());
                    (UploadStatus::Failure, Some(res.text().await?))
                }
                Err(e) => {
                    error!("failed to upload file. details = {}", e.to_string());
                    (UploadStatus::Failure, Some(e.to_string()))
                }
            };

        info!("successfully uploaded file {}", path);
        info!("status: {:#?}, message: {:#?}", status, message);

        self.notify(UploadEvent {
            path: path.to_string(),
            status: status.into(),
            message,
        })
        .await?;

        Ok(())
    }
/// Upload a file to an URL and notify
/// the remote server with an `UploadEvent`.
Upload a file to an URL and notify
the remote server with an `UploadEvent`.
Upload a file to an URL and notify the remote server with an ` UploadEvent ` .
pub async fn upload(&self, url: &str, path: &str, _file: File) -> Result<()> {
        debug!("reading file content in bytes. file={:?}", path);
        let buffer = std::fs::read(path)?;
        let (status, message): (UploadStatus, Option<String>) =
            match self.http_client.put(url).body(buffer).send().await {
                Ok(res) if res.status() == 200 => (UploadStatus::Success, None),
                Ok(res) => {
                    error!("Server responded with status code {}", res.status());
                    (UploadStatus::Failure, Some(res.text().await?))
                }
                Err(e) => {
                    error!("failed to upload file. details = {}", e.to_string());
                    (UploadStatus::Failure, Some(e.to_string()))
                }
            };
        info!("successfully uploaded file {}", path);
        info!("status: {:#?}, message: {:#?}", status, message);
        self.notify(UploadEvent {
            path: path.to_string(),
            status: status.into(),
            message,
        })
        .await?;
        Ok(())
    }
pub async fn upload ( & self , url : & str , path : & str , _file : File ) -> Result < ( ) > { debug ! ( " " path ) ; let buffer = std :: fs :: read ( path ) ? ; let ( status , message ) : ( UploadStatus , Option < String > ) = match self . http_client . put ( url ) . body ( buffer ) . send ( ) . await { Ok ( res ) if res . status ( ) == 200 => ( UploadStatus :: Success , None ) , Ok ( res ) => { error ! ( " " res status ( ) ) ; ( UploadStatus :: Failure , Some ( res . text ( ) . await ? ) ) } Err ( e ) => { error ! ( " " e to_string ( ) ) ; ( UploadStatus :: Failure , Some ( e . to_string ( ) ) ) } } ; info ! ( " " path ) ; info ! ( " " status message ) ; self . notify ( UploadEvent { path : path . to_string ( ) , status : status . into ( ) , message , } ) . await ? ; Ok ( ( ) ) }
Upload a file to an URL and notify
the remote server with an `UploadEvent`.
Upload a file to an URL and notify the remote server with an ` UploadEvent ` .
&self
url
&str
path
&str
_file
File
&self
url
&str
path
&str
_file
File