mongoose-crate-gcs
v1.1.1
Published
mongoose-crate StorageProvider that uploads files to Google Cloud Services
Downloads
27
Maintainers
Readme
mongoose-crate-gcs
A StorageProvider for mongoose-crate that stores files in Google Cloud Storage.
Usage
var mongoose = require('mongoose'),
crate = require('mongoose-crate'),
GCS = require('mongoose-crate-gcs')
var PostSchema = new mongoose.Schema({
title: String,
description: String
})
PostSchema.plugin(crate, {
storage: new GCS({
iss: 'A Google service account email',
bucket: 'Google Cloud Storage bucket',
keyFile: '/path/to/keyfile', // pass either key or keyFile
key: 'key as a string', // pass either key or keyFile
scope: '<scope-here>', // defaults to https://www.googleapis.com/auth/devstorage.full_control
acl: '<acl-here>', // defaults to public-read
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
});