5 个版本
0.2.8 | 2021 年 5 月 19 日 |
---|---|
0.2.7 | 2021 年 4 月 19 日 |
0.2.4 | 2021 年 3 月 19 日 |
#1425 在 开发工具
每月 25 次下载
32KB
756 行
rust-dropbox
一个便捷的工具,绑定到 Dropbox APIv2,现在可以操作 user_check
、upload(文件大小小于 150 MB)
、move
和 download
。它将处理 Dropbox API 的错误消息。并且有一个可以通过特性 non-blocking
激活的异步 API。
使用时,你需要 Dropbox 访问令牌
安装
- 在 crates.io 上找到
- 使用 cargo-edit
cargo add rust-dropbox
如何使用
阻塞 API
- 上传
use rust_dropbox::*
use std::env;
use std::{
fs::File,
io::Read,
};
let token = env::var("DROPBOX_TOKEN").unwrap();
let mut file = File::open("./profile.jpg").unwrap();
let mut buf: Vec<u8> = Vec::new();
file.read_to_end(&mut buf).unwrap();
let client = client::DBXClient::new(&token);
let option = UploadOptionBuilder::new().build();
let res = client.upload(buf, "/test/profile.jpg", option);
assert!(res.is_ok())
- 移动
use rust_dropbox::*
use std::env;
let token = env::var("DROPBOX_TOKEN").unwrap();
let client = client::DBXClient::new(&token);
let option = MoveCopyOptionBuilder::new()
.allow_ownership_transfer()
.allow_shared_folder()
.allow_auto_rename()
.build();
let res = client.move_file("/test/profile.jpg", "/profile.jpg", option);
assert!(res.is_ok())
- 下载
use rust_dropbox::*
use std::env;
use std::{
fs::File,
io::Write,
};
let token = env::var("DROPBOX_TOKEN").unwrap();
let client = client::DBXClient::new(&token);
let res = client.download("/profile.jpg");
let bytes = res.unwrap();
let mut file = File::create("new_profile.jpg").unwrap();
file.write_all(&bytes).unwrap();
要使用非阻塞 API
rust-dropbox={version=*,default-features=false,features=["non-blocking"]}
依赖
~0.7–13MB
~161K SLoC