mongoose-crate-localfs
v1.1.4
Published
mongoose-crate StorageProvider that stores files on the local filesystem
Downloads
27
Maintainers
Readme
mongoose-crate-localfs
A StorageProvider for mongoose-crate that stores files on the local filesystem.
Usage
const mongoose = require('mongoose')
const crate = require('mongoose-crate')
const LocalFS = require('mongoose-crate-localfs')
const path = require('path')
const PostSchema = new mongoose.Schema({
title: String,
description: String
})
PostSchema.plugin(crate, {
storage: new LocalFS({
directory: '/path/to/storage/directory',
path: (attachment) => `/${path.basename(attachment.path)}` // where the file is stored in the directory - defaults to this function
}),
fields: {
file: {}
}
})
const Post = mongoose.model('Post', PostSchema)
.. then later:
var post = new Post()
post.attach('image', {path: '/path/to/image'}, (error) => {
// file is now attached and post.file is populated e.g.:
// post.file.url
})