Last active
June 24, 2021 16:58
-
-
Save WingofaGriffin/0847e680ed0f1ca522de19885c522b84 to your computer and use it in GitHub Desktop.
Revamp of "Start Media Download" API reference to handle media files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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