Files Storage
About assets
You can make use of Asset
to store file references such as images and videos on the database. An asset can only be saved with a record but not as a standalone upload. Skygear automatically uploads the files to a S3 bucket assigned to your app. You can also use your own file storage bucket. More settings can be found at the Developer Portal.
Creating an asset
For example, you want to allow users to upload an image as an image
to his SKYRecord
. Once the user has selected the image to upload, you can save it by:
In Skygear SDK 1.6 or later, assets are uploaded automatically when you save
a record, so you do not need to call uploadAsset
separately.
Asset names will never collide. i.e. you can upload multiple assets with the same asset name.
asset.name
is rewritten after the asset being uploaded.
Querying an asset
SKYAsset.url
will be populated with an expiry URL after fetching /
querying the record from server.
Frequently Asked Questions
Is there limit to file upload on Skygear Cloud?
Currently, It is possible to upload file to Skygear Cloud with a maximum size of 50MB.
Is it possible to add CORS settings to file upload?
If you use Skygear Cloud, a CORS settings of *
(any origin) is added to all
files, so you can fetch your assets using scripts from any origin. If you have
your own S3 bucket, follow the Cross-Origin Resource Sharing guide.
when downloading files