Skip to content

Instantly share code, notes, and snippets.

@slamb2k

slamb2k/download.js

Created May 5, 2017
Embed
What would you like to do?
MobileCenterBuildDownload
function downloadOutput(buildId) {
util.debug("Getting build output for Build Id: {0}", buildId);
// Construct build output Url
var buildOutputUrl = `${mobileCenterBaseUrl}/builds/${buildId}/downloads/build`;
var options = {
url: buildOutputUrl,
headers: {
"X-API-Token": apiToken,
"Accept": "application/json",
"Content-Type": "application/json"
}
};
return request(options)
.then(function (body) {
// Parse the response so we can get the build detail
var buildOutputDetail = JSON.parse(body);
return (buildOutputDetail.uri);
}).then(function (uri) {
var file = fs.createWriteStream(MobileCenterBuildArtifacts);
var downloadRequest = request(uri).pipe(file);
downloadRequest.on('error', function (err) { util.debug("Error downloading build output: {0}", err); });
downloadRequest.on('finish', function () { file.close(function () { util.debug("Download complete: {0}", MobileCenterBuildArtifacts); }) });
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.