1.1.4 • Published 10 years ago

mongoose-crate-localfs v1.1.4

Weekly downloads
43
License
-
Repository
github
Last release
10 years ago

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

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

12 years ago

1.1.0

12 years ago

1.0.3

12 years ago

1.0.2

12 years ago

1.0.1

12 years ago

1.0.0

12 years ago