Skip to content

SnidelyWhiplash/mongoose-crate-s3

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IMPORTANT

This is a fork of the mongoose-crate-s3 repository here: https://github.com/achingbrain/mongoose-crate-s3

It exists solely to use a forked version of its knox dependency, which exists solely to fix an issue with a breaking change in knox's mime dependency.

mongoose-crate-s3

Dependency Status devDependency Status Build Status Coverage Status

A StorageProvider for mongoose-crate that stores files in Amazon S3 buckets

Usage

var mongoose = require('mongoose'),
  crate = require('mongoose-crate'),
  S3 = require('mongoose-crate-s3')

var PostSchema = new mongoose.Schema({
  title: String,
  description: String
})

PostSchema.plugin(crate, {
  storage: new S3({
    key: '<api-key-here>',
    secret: '<secret-here>',
    bucket: '<bucket-here>',
    acl: '<acl-here>', // defaults to public-read
    region: '<region-here>', // defaults to us-standard
    path: function(attachment) { // where the file is stored in the bucket - defaults to this function
      return return '/' + path.basename(attachment.path)
    }
  }),
  fields: {
    file: {}
  }
})

var Post = mongoose.model('Post', PostSchema)

.. then later:

var post = new Post()
post.attach('image', {path: '/path/to/image'}, function(error) {
  // file is now uploaded and post.file is populated e.g.:
  // post.file.url
})

Regions

By default the region is assumed to be us-standard. The region is used to assemble the endpoint so please specify a different one if you are hosting in Europe, for example.

A full list of valid S3 regions is available from the AWS documentation website.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%