rust-dropbox

Crates.iorust-dropbox
lib.rsrust-dropbox
version0.2.8
sourcesrc
created_at2021-03-11 14:06:07.536787
updated_at2021-05-19 12:00:17.768277
descriptiona convenient tool of dropbox-api binding, with non-blocking and blocking api
homepage
repositoryhttps://github.com/sinyo-matu/rust-dropbox
max_upload_size
id367304
size32,366
Yang Qin (sinyo-matu)

documentation

README

rust-dropbox

crate.io

A convenient tool binding to the Dropbox APIv2, Now it can operate user_check,upload(file size below 150 MB), move and download. It will handle error messages from Dropbox api. And there is a async api can be activate by feature non-blocking.

For use, you need a Dropbox access token

Installation

cargo add rust-dropbox

How to use

blocking api

  • upload
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())
  • move
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())
  • download
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();

To use non-blocking api

rust-dropbox={version=*,default-features=false,features=["non-blocking"]}
Commit count: 28

cargo fmt