feathers-mongoose-casl
Version 2.1.2
Version 2.1.2
  • feathers-mongoose-casl
  • Docs
    • Migrating
    • START A NEW PROJECT
      • Generate a new project.
      • install feathers-mongoose-casl
      • feathers-logger
      • Update config
      • Add mongoose
      • Email service
      • App hooks
      • Import required services
      • Verify user and filter user fields
      • Swagger, Logger, BodyParser
      • Email templates
      • public HTML
      • Run the server
      • Create you first user
      • vs code snippet extension
      • Test Login
      • Dashboard
      • Create a new Service with casl&Dashboard
      • Posts Postman snippet
      • Add Admin role
      • Done!
    • Advanced
      • Security - eslint-plugin-security
      • Security - rate limiting
      • Development tools
    • Guides
      • Throw errors
      • Auth Flow
      • Authentication
      • Authouriztion
      • /me
      • Rules Cache
      • Create a new service
      • Custom service validtor client data
      • validators
        • Example of use
        • Types
        • Mongoose schema
      • Default value
      • $Populate
      • Upload service
      • Upload files
        • Create upload service
        • Sign File After Populate
        • Storage support
          • Google-cloud
      • Error
      • feathers Client examples
      • Dashboard
        • Dashboard Config
          • Field configuration
          • doc Layout
          • custom Fields
            • customElements
        • Online dashboard
        • Add to your react app
      • customized feathers-mongoose-casl/services
      • Redis - in progress
      • S3
      • Postman
      • Swagger
      • debug
    • Production
      • ENV
    • Feathers wiki
      • Good links
    • utils
      • send email example
      • Async For Each
      • Create heroku server
      • pick
      • vs code snippet extension
      • Persist user request
    • Ecosystem
    • TODO
    • Versions updates
Powered by GitBook
On this page
  • Upload file to google-cloud
  • 1- Finish this guide
  • 2- Create google-cloud account
  • 3 - new bucket
  • 4- Update config json
  • 5- Update upload middleware configuration
  • 6- Update service validators
  • 7- Update service hooks
  • 8 - Done!

Was this helpful?

  1. Docs
  2. Guides
  3. Upload files
  4. Storage support

Google-cloud

PreviousStorage supportNextError

Last updated 5 years ago

Was this helpful?

Upload file to google-cloud

1- Finish this guide

2- Create google-cloud account

  1. Follow this 3 first steps of this

  2. Create secret-files folder in the src folder

  3. copy the JSON key file from google-cloud to src > secret-files and rename the file to secret-files.json

3 - new bucket

  1. Create new bucket

4- Update config json

path: config > default.json

  1. Update projectId and bucket name

    "google-cloud": {
        "projectId": "THIS IS THE PROJECT NAME",
        "bucket": "THE BOCKET NAME",
        "keyFilename": "../src/secret-files/google-key.json",
        "signedUrlExpires" : 900
      },
  2. Allow google-cloud

      "feathers-mongoose-casl": {
        "uploads": {
          "services": {
            "s3": false,
            "local-private": true,
            "local-public": true,
            "google-cloud": true // This need to be true
          }
          ....

5- Update upload middleware configuration

path: src > services > [YOUR_SERVICE_NAME] > [YOUR_SERVICE_NAME].service.js

  app.use('/organizations-files',
    uploadMiddleware({
      app,
      fileKeyName: 'file',
      serviceName: 'YOUR_SERVICE_NAME',
      storageService: STORAGE_TYPES['google-cloud'], // That's the change we made
      publicAcl: false,
      // mimetypes: ['image/png','image/jpeg'] // optional
    }),
    createService(options)
  );

6- Update service validators

path: src > validators > [YOUR_SERVICE_NAME].validators.js

const {Joi, enums} = require('feathers-mongoose-casl');

const getJoiObject = function(withRequired) {
  const required = withRequired ? 'required' : 'optional';
    return Joi.object({
    storage: Joi.string().valid(
      enums.STORAGE_TYPES['google-cloud'], //We need to add this line
      enums.STORAGE_TYPES['others'], // When user pass link to file
      ).meta({ dashboard: { hide: 1 }})
    ...
    })
}

7- Update service hooks

path: src > services > [YOUR_SERVICE_NAME] > [YOUR_SERVICE_NAME].hooks.js

const {hooks} = require('feathers-mongoose-casl');
const {uploadsHooks} = hooks;

const uploadHookConfig = {
  serviceName: 'YOUR_SERVICE_NAME',
  fileKeyName: 'file',
  singUrlKeyName: 'file',
  privateFile: true,
  autoSignUrl: true,
  userKeyName: 'user'
};


module.exports = {
  before: {
    all: [uploadsHooks(uploadHookConfig)],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  },

  after: {
    all: [uploadsHooks(uploadHookConfig)],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  },
}

8 - Done!

test the service

test from dashboard : 1) open and try to upload a file

feathersjs-mongoose-casl-admin
Create upload service
guide