#api-bindings #api #dropbox #async-api #file-upload

rust-dropbox

一个便捷的 Dropbox API 绑定工具,具有非阻塞和阻塞 API

5 个版本

0.2.8 2021 年 5 月 19 日
0.2.7 2021 年 4 月 19 日
0.2.4 2021 年 3 月 19 日

#1425开发工具

每月 25 次下载

MIT 许可证

32KB
756

rust-dropbox

crate.io

一个便捷的工具,绑定到 Dropbox APIv2,现在可以操作 user_checkupload(文件大小小于 150 MB)movedownload。它将处理 Dropbox API 的错误消息。并且有一个可以通过特性 non-blocking 激活的异步 API。

使用时,你需要 Dropbox 访问令牌

安装

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