Nitro Powered Motorcycles

    mongoose-crate-gcs

    1.1.1 • Public • Published

    mongoose-crate-gcs

    Dependency Status devDependency Status Build Status Coverage Status

    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
    });

    Install

    npm i mongoose-crate-gcs

    DownloadsWeekly Downloads

    1

    Version

    1.1.1

    License

    ISC

    Last publish

    Collaborators

    • achingbrain