Skip to content

blissbooker/mongoose-attachment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mongoose-attachment

Build Status Dependency Status Code Climate

Configuration

Filesystem Storage

var mongoose = require('mongoose');
var attachment = require('mongoose-attachment');

var Asset = new mongoose.Schema({});

Asset.plugin(attachment, {
    strategy: 'filesystem',
    attribute: 'image',
    config: {
        path: '/tmp/system',
        url: '/system'
    }
});

module.exports = Asset;

Usage

var params = {
  asset: {
    image: {
      filename: 'foobar.png',
      fileSize: 300000,
      contentType: 'image/png'
    }
  },
  path: 'path/to/foobar.png'
};

var asset = new Asset(params.asset);
asset.attach(params.path, function (err) {
    if (err) {
        return fn(err);
    }
    asset.save();
});

asset.toJSON();
{
  "_id": "548831d1e61bb2464310e803",
  "image": {
      "filename": "foobar.png",
      "fileSize": 300000,
      "contentType": "image/png",
      "url": "/system/548831d1e61bb2464310e803.png"
  }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published