Last active
March 16, 2021 09:13
-
-
Save Kirill255/7a992c1f4553cccb739d1a7e6938cd89 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// https://stackoverflow.com/questions/5294470/writing-image-to-local-server | |
// requirements: `npm i request` | |
const fs = require("fs"); | |
const request = require("request"); | |
/* | |
const fs = require("fs"); | |
const request = require("request"); | |
request.get({ | |
url: "https://app.wazzup24.com/api/v1/messages/content/ffd4713a-b0d4-40be-bb5c-c4e9e8946297", | |
encoding: "binary" | |
}, (err, response, body) => { | |
if (err) return console.log(err); | |
let filename = 'default.jpeg' | |
const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/; | |
let matches = filenameRegex.exec(response.headers['content-disposition']); | |
if (matches) filename = decodeURI(matches[1].replace(/['"]|UTF-8/g, '')); | |
console.log(filename) | |
fs.writeFile(filename, body, "binary", (err) => { | |
if (err) return console.log(err); | |
console.log("The file was saved!"); | |
}); | |
}); | |
*/ | |
request("https://s1.1zoom.ru/b5050/96/Cats_Glance_Paws_444682_1920x1200.jpg").pipe(fs.createWriteStream("cat.png")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment