Skip to content

v2.2.0

Latest
Compare
Choose a tag to compare
@panghu-huang panghu-huang released this 23 Feb 04:25
fe2b45b

🎉 Features

  • Support using files as request body or sending multipart/form-data requests
use octocrate::{repos, APIConfig, GitHubAPI, PersonalAccessToken};
use tokio::fs::File;

#[tokio::main]
async fn main() {
  let file_path = std::path::Path::new("test.txt");

  // File is from tokio::fs module
  let file = File::open(file_path).await.unwrap();
  // Get the file's length
  let content_length = file.metadata().await.unwrap().len();

  let query = repos::upload_release_asset::Query::builder()
    .name("test.txt")
    .build();

  let release_asset = github_api
    .repos
    .upload_release_asset("panghu-huang", "octocrate", release.id)
    .query(&query)
    // Set the content type of the file
    .header("Content-Type", "text/plain")
    // Set the content length of the file
    .header("Content-Length", content_length.to_string())
    // Set the file content
    .file(file)
    .send()
    .await
    .unwrap();

  // ..
}

Full Changelog: v2.0.1...v2.2.0