File Upload

Request a file upload ticket to upload directly to MediaSilo

Requesting an upload ticket returns all information necessary to perform a file upload (POST, PUT) directly to MediaSilo. This is especially useful for building applications that synchronize directories to MediaSilo or bridge a local asset management system with MediaSilo in the cloud. The returned data allows you to perform a normal PUT with a file object.

Files uploaded using this process are limited to 5 GB per file or less.

AttributeDescription
fileNameThis is the file name as it will be stored in S3. It does not have to be the actual name of the local file.

Step 1: Create the Upload Ticket

Let's assume we sent the following request to obtain an upload ticket:

POST /v3/assets/upload
{
    "fileName": "myfile.mov"
}

And we receive the following payload in response:

// 200 OK
{
    "assetUrl": "https://s3.amazonaws.com/ingest-east.mediasilo.com/26a35865-ffff-bbbb-b9af-1999d2c7835b/myfile.mov",
    "amzDate": "Mon, 19 Jan 2015 19:17:33 GMT",
    "amzAcl": "private",
    "contentType": "video/quicktime",
    "authorization": "AWS AKIAIFFFICBLRC7JU6RA:bF4dV+HkF30vCct4V1/uRKjPDFo=",
    "httpMethod": "PUT"
}
AttributeDescription
assetUrlThis is the URL to be used in your subsequent POST. It must remain unchanged.
amzDateThe date of the request. Must remain unchanged.
amzAclAlways private. Files uploaded this way are not publicly accessible. Requesting the file after upload will result in a 403 error. Only MediaSilo servers can access the uploaded file.
contentTypeThe file's content mime type which was automatically determined.
authorizationThis is is a one time, time limited signature that acts as an authentication string. Must remain unchanged.
httpMethodThe suggested method for file upload.

This response contains all we need to start the upload process.

Step 2: Upload file

File upload can be done in a browser (via JavaScript) or using any number of server side languages (Java, PHP, Python, Node, etc.). See the following examples in JavaScript and CURL (command line).

For supported file types, take a look at our support documents.

curl -X PUT "**assetUrl**" -H "Authorization: **authorization**" -H "x-amz-acl: **amzAcl**" -H "Content-Type: **contentType**" -H "x-amz-date: **amzDate**" -T **path/to/local/file**
function uploadFile(fileObject) {
	xhr = new XMLHttpRequest();
  xhr.open('PUT', 'https://s3.amazonaws.com/ingest-east.mediasilo.com/26a35865-ffff-bbbb-b9af-1999d2c7835b/myfile.mov', true);
  xhr.setRequestHeader('x-amz-date', 'Mon, 19 Jan 2015 19:17:33 GMT');
  xhr.setRequestHeader('Authorization', 'AWS AKIAIFFFICBLRC7JU6RA:bF4dV+HkF30vCct4V1/uRKjPDFo=');
  xhr.setRequestHeader('x-amz-acl', 'private');
  xhr.setRequestHeader('Content-Type', 'video/quicktime');
  xhr.send(fileObject);
}
curl -X PUT "https://s3.amazonaws.com/ingest-east.mediasilo.com/26a35865-ffff-bbbb-b9af-1999d2c7835b/MyVideo.mov" -H "Authorization: AWS AKIAIFFFICBLRC7JU6RA:bF4dV+HkF30vCct4V1/uRKjPDFo=" -H "x-amz-acl:private" -H "Content-Type: video/quicktime" -H "x-amz-date: Mon, 19 Jan 2015 19:17:33 GMT" -T videos/MyVideo.mov

📘

Data Fields

All data needs to be passed along exactly as it was returned in the ticket request.

3. Create Asset

Once the file is uploaded successfully you have 24 hours to create an asset before the content is deleted. create the asset using the API as usual.

The Version example shows how to create an asset that is a version of another asset. The asset being created will become the active version.

POST /v3/assets
{
    "sourceUrl": "https://s3.amazonaws.com/ingest-east.mediasilo.com/26a35865-282f-4aa2-b9af-1999d2c7835b/myfile.mov",
    "projectId": "0XXXCC-014B-2XX0-CF518DXXXX393E"
}
POST /v3/assets
{
    "sourceUrl": "https://s3.amazonaws.com/ingest-east.mediasilo.com/26a35865-282f-4aa2-b9af-1999d2c7835b/myfile.mov",
    "projectId": "0XXXCC-014B-2XX0-CF518DXXXX393E",
    "versionAssetId" : "9X7XDD-0x4B-2XX0-SEXX8DXXX393E",
    "versionId" : "Name of the Version"//This is optional
}

Here is a full JavaScript example:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>MediaSilo API - JavaScript Upload Example</title>

    <script>
        var hostname = '';
        var username = '';
        var password = '';
        var projectId = '';

        function createUploadTicket() {
            var filepath = document.getElementById('file').value;
            var filename = filepath.replace(/^.*?([^\\\/]*)$/, '$1');

            xhrTicket = new XMLHttpRequest();
            xhrTicket.open('POST', 'https://api.mediasilo.com/v3/assets/upload', true);
            xhrTicket.setRequestHeader('Authorization', 'Basic '+ btoa(username+":"+password));
            xhrTicket.setRequestHeader('Content-Type', 'application/json');
            xhrTicket.setRequestHeader('MediaSiloHostContext', hostname);
            xhrTicket.onreadystatechange = function() {
                if (xhrTicket.readyState == 4 && xhrTicket.status == 200) {
                    uploadFile(xhrTicket.responseText);
                }
            }
            xhrTicket.send(JSON.stringify({'fileName':filename}));
        }

        function uploadFile(uploadTicket) {
            var fileObject = document.getElementById('file').files[0];
            var uploadTicketObject = JSON.parse(uploadTicket);

            xhrUpload = new XMLHttpRequest();
            xhrUpload.open('PUT', uploadTicketObject.assetUrl, true);
            xhrUpload.setRequestHeader('x-amz-date', uploadTicketObject.amzDate);
            xhrUpload.setRequestHeader('Authorization', uploadTicketObject.authorization);
            xhrUpload.setRequestHeader('x-amz-acl', uploadTicketObject.amzAcl);
            xhrUpload.setRequestHeader('Content-Type', uploadTicketObject.contentType);
            xhrUpload.onreadystatechange = function() {
                if (xhrUpload.readyState == 4 && xhrUpload.status == 200) {
                    createAsset(uploadTicketObject.assetUrl);
                }
            }
            xhrUpload.send(fileObject);
        }

        function createAsset(assetPath) {
            xhrCreate = new XMLHttpRequest();
            xhrCreate.open('POST', 'https://api.mediasilo.com/v3/assets', true);
            xhrCreate.setRequestHeader('Authorization', 'Basic '+ btoa(username+":"+password));
            xhrCreate.setRequestHeader('Content-Type', 'application/json');
            xhrCreate.setRequestHeader('MediaSiloHostContext', hostname);
            xhrCreate.onreadystatechange = function() {
                if (xhrCreate.readyState == 4 && xhrCreate.status == 200) {
                    alert('Asset Created! Response: ' + xhrCreate.responseText);
                }
            }
            xhrCreate.send(JSON.stringify({'sourceUrl':assetPath, 'projectId':projectId}));
        }

    </script>

  </head>
  <body>
    <span>File</span>
    <input type="file" id="file" name="file" size="10"/>
    <input id="uploadbutton" type="button" value="Upload" onclick="createUploadTicket();"/>
  </body>
</html>
Language
Credentials
:
Click Try It! to start a request and see the response here!