Menu

Expand
Rate 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

Install the Assets Plugin

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

Initialize the plugin

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

Upload an asset

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

List your assets

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

Let's work together

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

Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Community Forums or browsing the Twilio tag on Stack Overflow.

        
        
        

        Thank you for your feedback!

        We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!

        Refer us and get $10 in 3 simple steps!

        Step 1

        Get link

        Get a free personal referral link here

        Step 2

        Give $10

        Your user signs up and upgrade using link

        Step 3

        Get $10

        1,250 free SMSes
        OR 1,000 free voice mins
        OR 12,000 chats
        OR more