> For the complete documentation index, see [llms.txt](https://feathersjs-mongoose.gitbook.io/feathers-mongoose-casl/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://feathersjs-mongoose.gitbook.io/feathers-mongoose-casl/docs/guides/upload-files/storage-support/google-cloud.md).

# Google-cloud

### Upload file to google-cloud&#x20;

### &#x20;1- Finish this guide

{% content-ref url="/pages/-LjJi1xfbWKjxNJ\_wo88" %}
[Create upload service](/feathers-mongoose-casl/docs/guides/upload-files/create-upload-service.md)
{% endcontent-ref %}

###

### 2- Create google-cloud account

1. Follow this 3 first steps of this [guide](< https://medium.com/@iwozzy/easily-host-images-with-node-and-google-cloud-storage-29fb14e2cdb8>)
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. &#x20;Create new bucket<br>

   ![](/files/-LjU-GpBpz1EZXSE7EYa)

###

### 4- Update config json

**path**: config > default.json<br>

1. Update projectId and bucket name<br>

   ```javascript
   "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<br>

   ```javascript
     "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

```javascript
  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

```javascript
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

```javascript
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 [feathersjs-mongoose-casl-admin](/feathers-mongoose-casl/docs/start-new-project-1/install-feathers-mongoose-casl.md) and try to upload a file


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://feathersjs-mongoose.gitbook.io/feathers-mongoose-casl/docs/guides/upload-files/storage-support/google-cloud.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
