-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
template for donwloading, still buggy
- Loading branch information
Showing
3 changed files
with
74 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const axios = require('axios'); | ||
const fs = require('fs').promises; | ||
|
||
/** | ||
* Kevin Pan | pan261@purdue.edu | Last Modified: 11/22/2021 | ||
* | ||
* Downloads a file by making a GET request on the storageUrl and then | ||
* saves the file as `filename` under the `destination` directory | ||
* @param {String} storageUrl | ||
* @param {String} fileName | ||
* @param {String} destination | ||
* @param {Object} credentials | ||
*/ | ||
exports.download = async (storageUrl, fileName, destination, credentials) => { | ||
await axios({ | ||
method: 'GET', | ||
url: storageUrl, | ||
headers: { | ||
Authorization: `Bearer ${credentials.access_token}` | ||
} | ||
}) | ||
.then(async res => { | ||
fs.writeFile(`./${destination}/${fileName}`, res.data).then(() => { | ||
console.log("finished downloading", fileName); | ||
}); | ||
}) | ||
.catch(err => { | ||
console.log("error while processing " + fileName); | ||
// console.log(err); | ||
}); | ||
} | ||
|
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
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