How to Upload an Audio File for Twillio Studio

Assets

This Twilio product is currently available as a Beta release. Some features are non withal implemented and others may exist changed before the product is declared equally Mostly Available. Beta products are not covered by a Twilio SLA. Larn more about beta production support.

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

How Assets piece of work

Twilio provides you with three unlike types of Assets: public, protected, and private. The primary divergence betwixt the types is how they are accessed:

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

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

Warning about use of public Assets

Anyone with the URL to a public nugget will be able to admission it. Therefore, customers should be thoughtful well-nigh what data they include in a public asset.

Metadata warning

Asset files are uploaded equally is, with all metadata persisted. If your asset files incorporate metadata, that will be stored with the file. An case would be exif metadata stored with an image. If you are making files available, please note that metadata is persisted and non removed/changed by the Assets product in any style.

Go started with Avails

First past opening one of your existing Services, or past creating a new 1. Once y'all're in the Functions Editor UI for your Service at that place are 3 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 push button, which will trigger an upload and deploy of your Assets (along with whatsoever Functions)
Assets UI points of interest

Upload a file by clicking Add+ and and so Upload File in the resulting menu, which will open up up a standard file upload dialogue. Once you've selected a file or files, you'll be presented with options to set the visibility of each Asset, as well as the power to remove or add together other files. Click Upload to brainstorm uploading your selection of files with the desired settings.

upload assets UI

While the Asset has been uploaded, it will not be immediately accessible via a URL or in your Functions yet. This will be indicated by the grey circle next to the Asset'due south name. To deploy the Asset (and the rest of your Service), click the Deploy All button. Later on a brief period, the deployment will end and y'all should encounter a dark-green cheque appear side by side to all deployed Avails.

Assets once deployed

Get the URL of an Nugget

In general the URL of one of your Avails can be adamant by taking the URL of your Service, for instance https://example-1234.twil.io, and appending the proper noun of your Asset.

In the case of an Nugget such as example.json in that Service, information technology tin exist accessed at https://example-1234.twil.io/example.json.

For a point and click solution, the Functions Editor UI also provides two ways to copy the URL of an Asset to your clipboard:

  • Open the context card of an Nugget, and click Copy URL
  • Open an Asset in the Functions Editor, and click the Re-create URL button that will announced below the content editor and above the logs pane
Copy an Asset url

Using public Avails

Public avails are publicly attainable one time deployed, and can be used by referencing their URL. For example: given a Service with the url of https://example-1234.twil.io and a public Asset named ahoy.mp3, the Asset will exist available at https://instance-1234.twil.io/ahoy.mp3.

Using protected Avails

The process for determining the URL of a protected Asset is the same as that of a public Asset. Even so, the Asset will only exist attainable from Twilio code such as a Function, Studio Flow, or Flex.

For instance, suppose we accept an image grumpy.jpg that's been deployed to https://twilio-assets-1967.twil.io/grumpy.jpg. Nosotros would like to be able to send this image to users as function of an MMS, simply otherwise have the file inaccessible. If the following code were deployed to a Function in the same Service and executed, the recipient will recieve the image of grumpy cat, but anybody else trying to access the file past URL will be returned a 403 Forbidden error instead.

                  

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

For case, if the audio were a protected Asset deployed at https://twilio-assets-1967.twil.io/sensitive-message.mp3, information technology could be referenced in your Studio Period equally shown below:

Say/Play a protected Asset

Using private Assets

When Twilio builds your Role for deployment it will packet any and all Individual Assets that you take uploaded. This makes Private Assets perfect for storing sensitive configuration files, templates, and shared code that supports your application.

In gild to access a private Asset, you will need to leverage the Runtime.getAssets method and open the file straight using either the open helper method, or by using helper methods from the fs module every bit shown in the following examples.

                      

Example of how to read the contents of a Individual Asset

                      

Example of how to serve an audio file from a Private Nugget

Hosting a Root Asset

In some cases, such as when hosting an app with a landing folio, you want the root URL of your Service to return an Nugget in the browser. For case, you can visit root-asset-5802.twil.io/ which serves static HTML solely via Assets.

To reproduce this behavior, you volition need to utilize one of two special paths for a public Asset for your file (whether it be HTML, an paradigm, or anything else).

/

You may rename an Asset's path to /, and that Asset will be served on requests to the root URL of your Service. In the Console UI, information technology would look like this:

Root Asset Path

/assets/index.html

This path applies only to HTML files. Renaming an HTML file's path to /avails/alphabetize.html will crusade the Service to render that page on requests to the root URL of your Service. It would await like this in the Console UI:

Assets Index.html Path

You tin practice this yourself using the following index.html example code:

                  

If yous want to deploy a root Asset using the Serverless Toolkit instead, yous will need to create the /assets/index.html path within the existing assets/ folder that exists for your project.

The resulting path in your local filesystem volition be /assets/assets/alphabetize.html, and the folder heirarchy will be as follows:

.
├── assets
│ └── avails
│ └── index.html
├── functions
└── parcel.json

Limitations

All Services have limitations on the maximum commanded file size and quantity of each Asset blazon that tin can be uploaded:

Asset Type Maximum Size Quantity
Public 25 MB 1000 Avails
Private 10 MB 50 Assets
Protected 25 MB 1000 Avails

Need some assist?

We all practise sometimes; code is hard. Go help at present 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.

harbourshoubless1969.blogspot.com

Source: https://www.twilio.com/docs/runtime/assets

0 Response to "How to Upload an Audio File for Twillio Studio"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel