Last active
May 17, 2017 14:34
-
-
Save TheRyanHickman/d859258a7d73904d103926f9c325aa35 to your computer and use it in GitHub Desktop.
Saving a file with Node Js
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
/** 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