mongoose-crate-localfs

1.1.4 • Public • Published

mongoose-crate-localfs

Dependency Status devDependency Status Build Status Coverage Status

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
})

Package Sidebar

Install

npm i mongoose-crate-localfs

Weekly Downloads

1

Version

1.1.4

License

none

Last publish

Collaborators

  • achingbrain