0
爲什麼下載的圖像格式不正確?爲什麼下載的圖像格式不正確?
import * as fs from 'fs';
import * as request from 'request-promise-native';
const download = async (url) => {
console.log(`Downloading ${url}`);
const options = {
url,
resolveWithFullResponse: true,
};
const response = await request.get(options);
console.dir(response.headers);
return fs.writeFileSync('image.jpg', response.body);
};
const main = async() => {
try {
await download('https://dz2cdn1.dzone.com/storage/rc-covers/3339976-refcard-cover141.png');
} catch (e) {
console.error(e);
}
};
main().then(() => console.log('success')).catch((e) => console.log(e));
生成的圖像格式不正確,無法打開。任何想法是什麼導致這個問題,以及如何解決它?
[使用請求獲取Node.js中的二進制內容]可能重複(http://stackoverflow.com/questions/14855015/getting-binary-content-in-node-js-using-request) – GilZ