Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Upload assets using the Assets Plugin

The Assets Plugin is a Twilio CLI plugin that is part of the Serverless Toolkit. It allows you to create an Assets service that you can use as a bucket for static assets, like images or audio files, that you want to upload. You can then use these assets in your Twilio applications. For example, you can upload audio files that you then use in a <Play> verb during a Twilio Voice call, or upload images that you can send to your users via MMS or WhatsApp media messages.

How to use the Assets Plugin

how-to-use-the-assets-plugin page anchor

Install the Assets Plugin

install-the-assets-plugin page anchor

Before we can get started using the Assets Plugin we need to install it. As the Assets Plugin is a Twilio CLI plugin, you will need to install the Twilio CLI first. If you have already installed the Twilio CLI, carry on, otherwise follow the instructions for installing the Twilio CLI.

Once the Twilio CLI is installed you can install the Assets Plugin with the following command:

twilio plugins:install @twilio-labs/plugin-assets

The Assets Plugin has three commands: init, upload and list. The first thing you should do is run the init command. Running init will call the Twilio Functions and Assets API to create a new service and store the details about that service so that we can use it with the other commands.

twilio assets:init

The service will be given a random name which will feature in the domain name for the service. If you want to provide your own name, you can pass the --service-name flag to the command.

twilio assets:init --service-name my-cool-assets-service

With the plugin initialized you can now use it to upload static assets with the upload command. Pass the path of the file you want to upload to the command and it will be deployed to your service.

twilio assets:upload path/to/file

If you only want an asset to be accessible by a Twilio request, you can upload it as a protected asset when you pass the --protected flag.

twilio assets:upload path/to/file --protected

The last command allows you to list the assets you have uploaded to the service. Run it with:

twilio assets:list

Your assets, their SIDs, paths, URLs and visibility will be listed. If you want more, or fewer, properties you can select them by passing the --properties flag to the command:

twilio assets:list --properties sid,url,date_created

Or you can output all the properties as JSON:

twilio assets:list -o json

The Assets Plugin is open source as part of the Serverless Toolkit(link takes you to an external page). If you find any problems with this, please file an issue(link takes you to an external page) or even create a pull request(link takes you to an external page) to work together with us on the toolkit. We would love to hear your ideas and feedback!

Rate this page: