- Simple approach: using the
public_htmldirectory in your cloud code.
- More customized approach: using the
static_assetsdecorator to have a function specifying the locations of the static assets.
Put your static assets in a directory
The simplest way to serve static assets to your users is to put them into
a directory called
public_html in your cloud code directory. The static
assets you put in this folder will be automatically available at
For example, if your cloud code project contains a file saved at
./public_html/images/hero.png, your user will be able to access it
Declare your static assets using decorator
If your cloud code project is more complex,
or if you cannot put your static assets in the
you can also declare your static assets using the
decorator so that Skygear knows where to find your static assets.
import skygear from skygear.utils.assets import directory_assets def set_hello_world_assets(): return directory_assets('my-assets/files')
In the above example,
Skygear will find your static assets at
./my-assets/files/hero.png if the user makes a request to
directory_assets function returns the absolute path of the static assets
directory by specifying a path relative to the current directory,
or an absolute path.