๋ด ๋ ธ๋ ์๋ฒ์์ URL์์ png ์ด๋ฏธ์ง๋ฅผ ๋ค์ด๋ก๋ํ๊ณ ํ์ผ์ ์ฐ์ญ์์ค.
.get("https://url/for/png/file")
.on('error', function(err) {
console.log(err)
})
.on('response', function(response){
console.log(response.statusCode) // 200
console.log(response.headers['content-type']); // 'image/png'
})
.on('complete', (resp: http.IncomingMessage, body: string | Buffer) => {
fs.writeFile(".../test.png", body, 'binary');
});
์ฃผ์ ๋ฌธ์ ๋ ์์ฑ๋ ํ์ผ์ด ์์๋์๋ค๋ ๊ฒ์ ๋๋ค(์ด ์ ์์).
๋์ on('complete'...) ๋์ ํ์ดํ๋ฅผ ์ฌ์ฉํ๋ฉด ์์ฑ๋ ํ์ผ์ด ์ ํํฉ๋๋ค.
.pipe(fs.createWriteStream(".../test.png"))
์ฐจ์ด์ ์ ์ ํํ ๋ฌด์์ด๋ฉฐ ํ์ผ์ ์ธ ์ ์๋๋ก ๋๋ฝ ๋ ๊ฒ์ ๋ฌด์์ ๋๊น?
๊ฐ์ ๋ฌธ์ .
์ธ์ฝ๋ฉ ์ฌ์ฉ: null ์ต์
@lambdacerro ๊ฐ์ฌํฉ๋๋ค. ๊ทธ๋ฌ๋ฉด ์ด ๋ฌธ์ ๋ฅผ ์ข ๋ฃํ๊ฒ ์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ธ์ฝ๋ฉ ์ฌ์ฉ: null ์ต์