Skip to content

Instantly share code, notes, and snippets.

@WingofaGriffin
Last active June 24, 2021 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WingofaGriffin/0847e680ed0f1ca522de19885c522b84 to your computer and use it in GitHub Desktop.
Save WingofaGriffin/0847e680ed0f1ca522de19885c522b84 to your computer and use it in GitHub Desktop.
Revamp of "Start Media Download" API reference to handle media files
const fetch = require("node-fetch");
const fs = require("fs");
const url = process.env.DOLBYIO_OUTPUT_URL;
const options = {
method: "GET",
headers: {
Accept: "application/octet-stream",
"x-api-key": process.env.DOLBYIO_API_KEY,
},
};
const path = process.env.LOCAL_FILE_PATH;
const downloadFile = async (url, options, path) => {
const res = await fetch(url, options);
const fileStream = fs.createWriteStream(path);
await new Promise((resolve, reject) => {
res.body.pipe(fileStream);
res.body.on("error", reject);
fileStream.on("finish", resolve);
});
};
downloadFile(url, options, path);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment