Working with Storage

Learn how to upload and retrieve files with Morph API.

Overview

Morph has a file storage system that allows users to upload files, create folders, and issue URL with expiry.

morph dashboard storage

This section shows how to use Morph Storage API to upload files, get file object and issue shared URL.

📘

Before you upload files via Morph API

Buckets, which are the root folders of Storage, cannot be created by the API. Be sure to create it from Dev Mode.

Structure

Storage consists of buckets as the root folder, folders under it, and files to be uploaded. Files can be placed directly under buckets without creating folders.

There is no limit to the number of buckets, folders, or files that can be created.

When importing using csv in the database table, the file uploaded there will be stored in this Storage. Also, if there is a field such as attachment or image in the table of Widget Dashboard, the file will be uploaded to the Storage when the record is added.

Create buckets in Storage

Buckets can only be created in Dev mode. Open Dev mode and press the New Bucket button.

morph storage create buckets

Enter a bucket name and select each permission option.

Permission

Permission is a level of access restriction for folders and files under the bucket. read is obtaining file information, create is for uploading files, and update is for overwriting files.

Please refer to the table below for the contents of each permission.

KeyTypeDescription
forbiddenstringUnable to access files via API
publicstringNo API Key is required to access files
limitedPublicstringAPI Key is required and accessible only from authorized IP addresses

Upload Files

Once the bucket is created, use the API to upload files.

curl -X POST 'https://{teamSlug}.api.morphdb.io/v0/storage/object/{bucketName}' \
--form 'key="morph-favicon.ico"' \
--form 'file=@"/morph-favicon.ico"' \
--header 'x-api-key: xxxxxxxxxxxxxxxxxxxxx'

📘

Set Header Content-Type

please set Content-type: multipart/form-data in header with key named file

After the upload is successful, the key of the uploaded file will be returned.

The characters start with v is timestamp prefix to cache files.

{
    "key": "v1685594922/morph-favicon.ico"
}

Get Object

Get the object of the uploaded file in the bucket.

curl -X GET 'https://{teamSlug}.api.morphdb.io/v0/storage/public/{bucketName}/morph-favicon.ico' \
--header 'x-api-key: xxxxxxxxxxxxxxxxxxxxx'

This endpoint returns file object and parameters of Accept-Ranges:type, Content-Type, Cache-Control, ETag, Content-Length, Content-Range in headers.

Query Parameters Option

add these parameters to request headers, the image file will be resized and returned.

KeyTypeDescription
wstringWidth (Changes image size if specified) [px]
hstringHeight (Changes image size if specified) [px]

Get Signed URL

Retrieve files uploaded to the bucket in URL format with expiration date.

curl -X GET 'https://{teamSlug}.api.morphdb.io/v0/storage/url/sign/{bucketName}/morph-favicon.ico' \
--header 'x-api-key: xxxxxxxxxxxxxxxxxxxxx'

The response is URL with expiration date.

📘

Signed URL expiry

Expiry is 1 hour as default. After the period is expired, nobody can access the url.

{
    "url": "https://{teamSlug}.api.morphdb.io/v0/storage/sign/{bucketName}/v1685594922/morph-favicon.ico?Expires=1685599917&Key-Pair-Id=K3VWHH8ZU74J1O&Signature=KFVQtvHpRbDci1yEF-AdVjXutxT88PwNAEgMxyucvOn3rxg7lFRBNX5ZSC2JNnwXS-UcJiDSYlJxUpDS6e4oPCq~yNsLF15R-W99IV8phcS7t2hR4LgUfYQ2UPGPIFCqKUGNQFkGSUSM-wNoUQbY0G4mBxxGHY0Y3yxF34-4MT4ZoOIPy0qpqnzxhujLWxoSzsCicV6pHKEQXNjQ3cL-a61G4B9TOmFGj3E0mAaQLZcC1Gh7ZVfH2Q6i4Ai~2cIpLt2OMfeExumxCPkYGZDWtsGG3Y1x8Gtjx7vaMsXR8KsRIxXvy7yTGUAQ6sgO6Jjb2bNywpXhnF~~lEHIn9LcZw__"
}