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.
```rust extern crate mongofilecenter;
use mongofilecenter::{FileCenter, FileData, mime};
const mongodburi: &str = "mongodb://localhost:27017/testmyfilestorage";
let filecenter = FileCenter::new(mongodburi).unwrap();
let file = filecenter.putfilebypath("/path/to/file", Some("filename"), Some(mime::IMAGEJPEG)).unwrap();
let fileid = file.getobject_id();
let idtoken = filecenter.encryptid(&fileid); // this token is safe in public
let fileid = filecenter.decryptidtoken(&id_token).unwrap();
let rfile = filecenter.getfileitembyid(&file_id).unwrap().unwrap();
match rfile.intofile_data() { FileData::GridFS(file) => { // do something } FileData::Collection(data) => { // do something } } ```
https://crates.io/crates/mongo-file-center
https://docs.rs/mongo-file-center