#mongodb #storage #file

mongo-file-center

To store perennial files and temporary files in MongoDB

25 releases

Uses new Rust 2021

0.6.4 Oct 25, 2021
0.5.0 May 2, 2021
0.4.2 Jul 29, 2020
0.4.0 Mar 17, 2020
0.1.7 Nov 16, 2018

#88 in Database interfaces

Download history 23/week @ 2021-08-11 62/week @ 2021-08-18 4/week @ 2021-08-25 1/week @ 2021-09-01 3/week @ 2021-09-08 2/week @ 2021-09-15 7/week @ 2021-09-22 21/week @ 2021-09-29 2/week @ 2021-10-06 22/week @ 2021-10-13 104/week @ 2021-10-20 129/week @ 2021-10-27 162/week @ 2021-11-03 85/week @ 2021-11-10 17/week @ 2021-11-17 25/week @ 2021-11-24

293 downloads per month
Used in 2 crates

MIT license

69KB
1.5K SLoC

File Center on MongoDB

CI

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 document or be separated into chunks to store in multiple documents. It depends on the size of data and the file_size_threshold. If the size is smaller than or equal to the threshold, it stores in a single document. The max threshold is 16770KB. The default threshold is 256KiB.

Example

extern crate mongo_file_center;

use mongo_file_center::{FileCenter, FileData, mime};

const mongodb_uri: &str = "mongodb://localhost:27017/test_my_file_storage";

let file_center = FileCenter::new(mongodb_uri).await.unwrap();

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

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).await.unwrap().unwrap();

match r_file.into_file_data() {
    FileData::Buffer(data) => {
        // do something
    }
    FileData::Stream(stream) => {
        // do something
    }
}

Migration Limitation

The old file center should not be migrated to the file center 0.6+ because the structure and the hash algorithm have been changed extremely. You will need a lot of effort to do that by yourself.

Crates.io

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

Documentation

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

License

MIT

Dependencies

~24MB
~526K SLoC