External Storage - Alibaba Cloud OSS

External Storage / Alibaba Cloud OSS

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

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

Authentication

When passing Alibaba Cloud credentials in your request JSON, you have to set the following authentication properties:

Attribute Type Description
provider String provider must be set to alibaba
key String Alibaba Cloud Access Key Id
secret String Alibaba Cloud Secret Access Key
{
    "store": {
        "provider": "alibaba",
        "key": "your-alibaba-key",
        "secret": "your-alibaba-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"
    }
}

Alibaba Cloud OSS properties and settings

Attribute Type Required Description
bucket String Yes Name of a destination bucket in your Alibaba Cloud OSS account.
region String Yes Name of the Alibaba Cloud Region in which your OSS bucket is located.
path String No Destination path in your OSS bucket (without leading slash). Defaults to root.
metadata Hash No Custom OSS Metadata.
headers Hash No Custom HTTP headers.

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

{
    "store": {
        "provider": "alibaba",
        "key": "your-alibaba-key",
        "secret": "your-alibaba-secret",
        "bucket": "bucket-name",
        "region": "alibaba-oss-region"
        "path": "assets/image.jpg",
        "metadata": {
            "key": "value"
        },
        "headers": {
            "Cache-Control": "max-age=2592000000"
        }
    }
}

An example cURL request of using Alibaba Cloud OSS as 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": {
        "provider": "alibaba",
        "key": "your-alibaba-key",
        "secret": "your-alibaba-secret",
        "bucket": "bucket-name",
        "region": "alibaba-oss-region"
        "path": "assets/image.jpg",
        "headers": {
            "Cache-Control": "max-age=2592000000"
        }
    }
}'

When using Alibaba Cloud OSS as your External Storage, the url property within the JSON response will point to the object's location within the OSS 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": "9fccf4b5-cfab-4e92-9276-5d2028fcb6a0",
    "input": {
        "name": "image.jpg",
        ..
    },
    "output": {
        "url": "https://bucket-name.oss-eu-central-1.aliyuncs.com/assets/image.jpg",
        ..
    }
}