Skip to main content

Basic Download

Using CURL command

For a given media object (VOD - not live) a user can request a file download for a particular offering (default is default) with either mp4 or prores format with optional start and end times (seconds, float). NOTE: An authorization token is required in order to obtain the necessary download permissions of the media object.

  1. Initiate a download POST /call/media/files
curl -X POST https://host-76-74-91-16.contentfabric.io/q/iq__283C4mvqMV62o88srZPzRtUA1bCb/call/media/files -d '{"format":"mp4", "offering":"default"}' -H "Authorization: Bearer $TOKEN"

Response:

{
"job_id":"tqlfinodMXMYGHMLHzxH2r5QrL7jK5wP4ve-iq__283C4mvqMV62o88srZPzRtUA1bCb-default--mp4-000000-000000"
}
  1. Check status GET /call/media/files/{job_id}
curl https://host-76-74-91-16.contentfabric.io/q/iq__283C4mvqMV62o88srZPzRtUA1bCb/call/media/files/tqlfinodMXMYGHMLHzxH2r5QrL7jK5wP4ve-iq__283C4mvqMV62o88srZPzRtUA1bCb-default--mp4-000000-000000 -H "Authorization: Bearer $TOKEN"

Response:

{
"offering": "default",
"format": "mp4",
"status": "completed",
"progress": 100
}
  1. Download the file GET /call/media/files/{job_id}/download

File name and content disposition are set automatically (since there is no need for the user to change the file name or the disposition)

https://host-76-74-91-16.contentfabric.io/q/iq__283C4mvqMV62o88srZPzRtUA1bCb/call/media/files/tqlfinodMXMYGHMLHzxH2r5QrL7jK5wP4ve-iq__283C4mvqMV62o88srZPzRtUA1bCb-default--mp4-000000-000000/download?authorization=$TOKEN

Using Eluvio Client

For a given media object (VOD - not live) a user can initialize the Eluvio Client to request a file download for a particular offering (default is default) with either mp4 or prores format with optional start and end times (seconds, float) by simply calling the MakeFileServiceRequest method call.

Sample Code

const { ElvClient } = require("@eluvio/elv-client-js");

const Download = async () => {
// Parameters
const versionHash = "hq__CV3hoSLZwLneto5wNBJGJJqgVUPVyaYErPdex6nFKC69SPaB782BGFEohTDEGG1JhZ9igUE65yw";
const format = "mp4";
const offerings = "default";
const filename = "MyFile.mp4";

try {
const client = await ElvClient.FromNetworkName({
networkName: "demo"
});

const wallet = client.GenerateWallet();
const signer = wallet.AddAccount({
privateKey: process.env.PRIVATE_KEY
});

client.SetSigner({signer});

// Start download job
const response = await client.MakeFileServiceRequest({
versionHash: versionHash,
path: "/call/media/files",
method: "POST",
body: {
format,
offerings,
filename
}
});

const jobId = response.job_id

// Check download job status until complete
let downloadJobStatus;
do {
// Wait 2 seconds between calls to status
await new Promise(resolve => setTimeout(resolve, 2000));

downloadJobStatus = await client.MakeFileServiceRequest({
versionHash: versionHash,
path: `/call/media/files/${jobId}`
});

console.log(`${(downloadJobStatus?.progress || 0).toFixed(1)} / 100`);
} while(downloadJobStatus?.status !== "completed");

// Download is finished, generate download url
const downloadUrl = await client.FabricUrl({
versionHash: versionHash,
call: `/media/files/${jobId}/download`,
service: "files",
queryParams: {
"header-x_set_content_disposition": `attachment; filename=${filename}`
}
});

console.log(downloadUrl);
} catch(error) {
console.error(error);
console.error(JSON.stringify(error, null, 2));
}
};

Download();