#mongodb #storage #file

mongo-file-center

To store perennial files and temporary files in MongoDB

14 releases

✓ Uses Rust 2018 edition

0.2.0 Sep 17, 2019
0.1.12 Jun 24, 2019
0.1.11 Apr 16, 2019
0.1.8 Mar 22, 2019
0.1.7 Nov 16, 2018

#71 in Database interfaces

Download history 40/week @ 2019-06-30 41/week @ 2019-07-07 2/week @ 2019-07-14 13/week @ 2019-07-21 18/week @ 2019-07-28 45/week @ 2019-08-04 14/week @ 2019-08-11 1/week @ 2019-08-18 158/week @ 2019-08-25 47/week @ 2019-09-01 54/week @ 2019-09-08 85/week @ 2019-09-15 106/week @ 2019-09-22 36/week @ 2019-09-29 2/week @ 2019-10-06

187 downloads per month
Used in 2 crates

MIT license

1.5MB
1K SLoC

File Center on MongoDB

Build Status

This crate aims to build an easy-to-use and no-redundant file storage based on MongoDB.

For perennial files, each of them is unique in the database, and can be retrieved many times without limitation.

For temporary files, they are allowed to be duplicated, but each instance can be retrieved only one time in a minute after it is created.

The file data can be stored in a collection or GridFS. It depends on the size of data. If the size is bigger than the threshold, it stores in GridFS, or it stores in a collection. The max threshold is 16770KB. The default threshold is 255KiB.

Temporary files are suggested to store in a collection, otherwise you have to clear the garbage in GridFS.

Example

extern crate mongo_file_center;
extern crate mime;

use mongo_file_center::{FileCenter, FileData};

const HOST: &str = "localhost";
const PORT: u16 = 27017;

let database = "test_my_file_storage";

let file_center = FileCenter::new(HOST, PORT, database).unwrap();

let file = file_center.put_file_by_path("/path/to/file", Some("file_name"), Some(mime::IMAGE_JPEG)).unwrap();

let file_id = file.get_object_id();

let id_token = file_center.encrypt_id(&file_id); // this token is safe in public

let file_id = file_center.decrypt_id_token(&id_token).unwrap();

let r_file = file_center.get_file_item_by_id(file_id).unwrap().unwrap();

match r_file.into_file_data() {
    FileData::GridFS(file) => {
        // do something
    }
    FileData::FileData(data) => {
        // do something
    }
}

Crates.io

https://crates.io/crates/mongo-file-center

Documentation

https://docs.rs/mongo-file-center

License

MIT

Dependencies

~8MB
~157K SLoC