This package allows for easy storage of blobs on the filesystem.
This package is not currently published to Atmosphere.
cd webapp/packages
git submodule add https://github.com/UCSC-MedBook/blobs
Inserting a blob on the server will move the original file!
Blobs2.create(pathToFileOnServer, associatedObject, metadata, callback)
pathToFileOnServer
: the path of the file on the serverassociatedObject
: the object the blob is associated with. This is an object with the fieldscollection_name
andmongo_id
.metadata
: any needed uniquely identifying information (any Object)
let blobId = Blobs2.create("/path/to/file/on/server", {
collection_name: "Jobs",
mongo_id: "YDcb7YWfXTdjXbSKX"
}, {}, function (err, result) {
// code
});
Blobs can be deleted using Blobs2.delete
, which takes a selector and a
callback function.
Calling Blobs2.delete
will also delete the files on disk.
let associated_object = {
collection_name: "Jobs",
mongo_id: "7bcYtNJx4G3NpEtCn",
}
Blobs2.delete({ associated_object }, (err, deletedCount) => {
if (err) {
console.log("Error deleting blobs!");
}
});
Blobs are stored at /filestore
, but this can be overridden by setting MEDBOOK_FILESTORE
in environment.
Within that folder, they are stored two folders down, according to the mongo _id
. If the mongo _id
is "abcdefg", the full storage path will be "/filestore/ab/cd/abcdefg".