External Storage - Google Cloud Storage

External Storage / Google Cloud Storage

In order to use Google Cloud Storage as your External Storage of choice, you must set the provider attribute to google within the store hash and, at a minimum, provide your Google credentials (key and secret) as well as a bucket name and the Google Cloud region where your bucket is located. The full list of store hash attibutes for Google Cloud Storage can be found below.

Alternatively, you can use our Secure Storage Connectors. Simply save your credentials in your Optidash Account and reference themy by ID. This mechanism will greatly increase the security of your cloud credentials. When Secure Storage Connectors are in use, you only have to provide Optidash API with your Connector id instead of provider, key, and secret properties. You can add new Connector in your Optidash Account.

In order to access and generate Google Developer Keys you must have "Interoperability" enabled.

To do so, open the Cloud Storage Settings page in the Google Cloud Platform Console and select Interoperability tab. Than, if you have not set up interoperability before, click "Enable interoperability access" and than "Create a new key".

Authentication

When passing Google Developer Keys in your request JSON, you have to set the following authentication properties:

Attribute Type Description
provider String provider must be set to google
key String Developer Access Key
secret String Developer Secret
{
    "store": {
        "provider": "aws",
        "key": "your-developer-key",
        "secret": "your-developer-secret"
    }
}

When using Secure Storage Connectors, you only need to provide your Connector ID:

Attribute Type Description
id String Secure Storage Connector ID
{
    "store": {
        "id": "your-connector-id"
    }
}

Google Cloud Storage properties and settings

Attribute Type Required Description
bucket String Yes Name of a destination bucket in your Google Cloud Storage account.
path String No Destination path in your Google Cloud Storage bucket (without leading slash).
Defaults to root.
acl String No The Access Control List in a JSON API-format of the destination object.
Defaults to "publicRead".
metadata Hash No Custom Metadata you would like to set on your object.
headers Hash No Custom HTTP headers you would like to set on your object.

The Optidash API allows you to set the following custom headers on your objects: Cache-Control, Content-Type, Content-Encoding, Content-Language and Content-Disposition.

An example cURL request of using Google Cloud Storage (with Connector ID) as an External Storage provider will look like the following:

curl https://api.optidash.ai/1.0/fetch -X POST -u your-api-key: \
-H "Content-Type: application/json" \
-d '{
    "url": "https://www.website.com/image.jpg",
    "resize": {
        "width": 100,
        "height": 75
    },
    "store": {
        "id": "your-connector-id",
        "bucket": "images",
        "path": "assets/image.jpg",
        "acl": "publicRead",
        "metadata": {
            "key": "value"
        },
        "headers": {
            "Cache-Control": "max-age=2592000000"
        }
    }
}'

When using Google Cloud Storage as your External Storage, the url property within the JSON response will point to the object’s location within the Google Cloud Storage bucket and you can safely use that URL in production, for example:

HTTP/1.1 200 OK

Status: 200 OK
Content-Type: application/json

{
    "success": true,
    "code": 200,
    "id": "5f17de07-d301-4154-9293-ba6d85285d39",
    "input": {
        "name": "image.jpg",
        ..
    },
    "output": {
        "url": "https://storage.googleapis.com/images/assets/image.jpg",
        ..
    }
}

Custom Bucket Permissions

If you would like to create a Google Cloud User dedicated only for the Optidash API or are using custom bucket permissions, please make sure that the user performing the API call has WRITER permissions.