1.2.0 • Published 7 years ago

mongoose-crate-s3 v1.2.0

Weekly downloads
52
License
-
Repository
github
Last release
7 years ago

mongoose-crate-s3

Dependency Status devDependency Status Build Status Coverage Status

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

Usage

const mongoose = require('mongoose')
const crate = require('mongoose-crate')
const S3 = require('mongoose-crate-s3')
const path = require('path')

const 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
    // where the file is stored in the bucket - defaults to this function
    path: (attachment) => `/${path.basename(attachment.path)}`
  }),
  fields: {
    file: {}
  }
})

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

.. then later:

const post = new Post()
post.attach('image', {
  path: '/path/to/image',

  // optionally send these additional headers
  headers: {
    'Content-Type': 'image/png'
  }
}, (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.

1.2.0

7 years ago

1.1.4

8 years ago

1.1.3

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago