added bit more verbose output and my build script.
also embedded demo of usage
This commit is contained in:
parent
4d5fc9c2a7
commit
6d2a4aa625
5 changed files with 18 additions and 7 deletions
11
src/main.rs
11
src/main.rs
|
@ -1,6 +1,5 @@
|
|||
use std::fs;
|
||||
use std::path::Path;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Deserialize;
|
||||
use reqwest::blocking::Client;
|
||||
use std::error::Error;
|
||||
|
||||
|
@ -45,9 +44,10 @@ fn upload_images_batch(client: &Client, config: &Config, images: &[String], batc
|
|||
let mut media_ids = Vec::new();
|
||||
|
||||
for image_path in images {
|
||||
println!("Uploading image {}", image_path.to_string());
|
||||
let form = reqwest::blocking::multipart::Form::new()
|
||||
.file("file", image_path)?;
|
||||
|
||||
|
||||
let res = client.post(&url)
|
||||
.bearer_auth(&config.access_token)
|
||||
.multipart(form)
|
||||
|
@ -67,7 +67,8 @@ fn upload_images_batch(client: &Client, config: &Config, images: &[String], batc
|
|||
"media_ids": media_ids,
|
||||
"visibility": config.visibility,
|
||||
});
|
||||
|
||||
|
||||
println!("Posting batch {} out of {}", batch_num, total_batches);
|
||||
client.post(&post_url)
|
||||
.bearer_auth(&config.access_token)
|
||||
.json(&body)
|
||||
|
@ -95,7 +96,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
let images = get_jpeg_files(&args[1]);
|
||||
let client = Client::new();
|
||||
let total_batches = (images.len() + config.batch_size - 1) / config.batch_size;
|
||||
|
||||
println!("Found a total of {} images to upload. Will take {} batches", images.len(), total_batches);
|
||||
for (i, chunk) in images.chunks(config.batch_size).enumerate() {
|
||||
upload_images_batch(&client, &config, chunk, i + 1, total_batches, &title)?;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue