3 stable releases
1.2.1 | Jul 6, 2023 |
---|---|
1.1.1 | Jun 30, 2023 |
1.0.0 |
|
#516 in Images
41 downloads per month
14KB
229 lines
imgbb-rs
ImgBB API wrapper for rust
Getting Started
- Register/Log in to ImbBB
- Obtain the API Key
- Use the API Key in with the library
Usage
Straightforward
use imgbb::ImgBB;
use tokio;
#[tokio::main]
async fn main() {
let imgbb = ImgBB::new("<API KEY>");
let res = match imgbb.upload_file_with_expiration("<PATH>", <SECONDS>).await {
Ok(res) => res,
Err(err) => {
println!("{}", err);
return;
}
};
println!("{:#?}", res);
}
With uploader
use imgbb::ImgBB;
use tokio;
#[tokio::main]
async fn main() {
let imgbb = ImgBB::new("<API KEY>");
let ul = imgbb
.read_file("<PATH>").expect("Unable to read file")
.expiration(<SECONDS>);
let res = match ul.upload().await {
Ok(res) => res,
Err(err) => {
println!("{}", err);
return;
}
};
println!("{:#?}", res);
}
Supported data types
- File & Path
imgbb.read_file("PATH").expect("Unable to read file").upload().await
// or
imgbb.upload_file("PATH").await
- Bytes (
AsRef<u8>
)
imgbb.read_bytes(&[u8]).upload().await
// or
imgbb.upload_bytes(&[u8]).await
- Base64 String
imgbb.read_base64("BASE64").upload().await
// or
imgbb.upload_base64("BASE64").await
License
imgbb-rs is licensed under the GNU GPL v3.0
Dependencies
~4–16MB
~219K SLoC