A StorageProvider for mongoose-crate that stores files in Google Cloud Storage.
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',
key: 'key as a string',
scope: '<scope-here>',
acl: '<acl-here>',
path: function(attachment) {
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) {
});