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

Assets


Twilio Assets is a static file hosting service that allows developers to quickly upload and serve the files needed to support their applications. With Twilio Assets you can host your files that support web, voice, and messaging applications. Twilio Assets is frequently used to host .mp3 audio files used in TwiML and Studio Flows, to serve images sent through MMS, or to store configuration used by Twilio Functions.


How Assets work

how-assets-work page anchor

Twilio provides you with three different types of Assets: public, protected, and private. The primary difference between the types is how they are accessed:

  • Public Assets are served over HTTPS from the Twilio CDN to ensure that they are highly available and secure, and are accessible by anyone with the Asset's URL.
  • Protected Assets are accessible via the Twilio CDN by URL as well, but require a valid Twilio request signature, or they will return a 403 error.
  • Private Assets are not accessible by URL or exposed to the web; instead, they are packaged with your Twilio Functions at build time.

If you would like to learn more about Asset visibility, we have a document that goes over the distinctions between public, protected, and private assets in greater detail.

(warning)

Warning about use of public Assets

Anyone with the URL to a public asset will be able to access it. Therefore, customers should be thoughtful about what data they include in a public asset.

(warning)

Metadata warning

Asset files are uploaded as is, with all metadata persisted. If your Asset files contain metadata, that will be stored with the file. An example would be EXIF metadata stored with an image. If you are making files available, please note that metadata is persisted and not removed/changed by the Assets product in any way.


Start by opening one of your existing Services, or by creating a new one. Once you're in the Functions Editor UI for your Service there are three points of interest:

  1. The Assets pane, which lists your Assets, their Visibility, a context menu for adjusting visibility, and another menu for other actions.
  2. The Add+ button which allows you to upload files as Assets, or create a new Asset.
  3. The Deploy All button, which will trigger an upload and deploy of your Assets (along with any Functions)
Assets UI points of interest.

_26
exports.handler = (context, event, callback) => {
_26
// Access the NodeJS Helper Library by calling context.getTwilioClient()
_26
const client = context.getTwilioClient();
_26
// Query parameters or values sent in a POST body can be accessed from `event`
_26
const from = event.From || '+15017122661';
_26
const to = event.To || '+15558675310';
_26
const body = event.Body || 'Ahoy, World!';
_26
_26
client.messages
_26
.create({
_26
to,
_26
from,
_26
body,
_26
// You will get a 403 if you try to view this image, but Twilio will
_26
// be able to access it and send it as part of the outgoing MMS
_26
mediaUrl: 'https://twilio-assets-1967.twil.io/grumpy.jpg',
_26
})
_26
.then((message) => {
_26
console.log(`Success! MMS SID: ${message.sid}`);
_26
return callback(null, message.sid);
_26
})
_26
.catch((error) => {
_26
console.error(error);
_26
return callback(error);
_26
});
_26
};

Similarly, suppose you have audio or messaging to include in your Studio Flow, but don't want that audio to be accessible to the entire internet. If the audio were uploaded as protected Asset, you could then reference its URL in the Studio Say/Play widget, and the audio will play for anybody that hits that part of your Flow.

For example, if the audio were a protected Asset deployed at https://twilio-assets-1967.twil.io/sensitive-message.mp3, it could be referenced in your Studio Flow as shown below:

Say/Play a protected Asset.Rate this page:

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.