Skip to content

Instantly share code, notes, and snippets.

@TheRyanHickman
Last active May 17, 2017 14:34
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 TheRyanHickman/d859258a7d73904d103926f9c325aa35 to your computer and use it in GitHub Desktop.
Save TheRyanHickman/d859258a7d73904d103926f9c325aa35 to your computer and use it in GitHub Desktop.
Saving a file with Node Js
/** Needed dependencies to make this work */
const request = require("request")
const fs = require('fs');
function saveFile(remoteFilePath)
{
/** Create folder path aligned to the category of the image, you may nest /uploads/[category] */
var folderPath = __dirname + "/folderPath"
var filename = folderPath + "/" + (new Date().getTime()).toString() + "-snapchat-chat.jpg"
/** Create the file stream */
var writeFile = fs.createWriteStream(filename)
/* Request the file and download to location */
request(remoteFilePath).pipe(writeFile).on('close', function() {
console.log(url, 'was saved to', filename)
});
}
saveFile("https://cdn.pttrns.com/574/7204_f.jpg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment