0
私はファイルをダウンロードするために以下のコードを使用しており、 ダウンロードファイルのサイズを取得しています。それは私に0値を与える。しかし、ファイルが正常にダウンロードされます。node.jsの画像ファイルのサイズを取得する方法は?
var download = function(uri, filename, callback){
BASE.request.head(uri, function(err, res, body){
console.log('content-type:', res.headers['content-type']);
console.log('content-length:', res.headers['content-length']);
BASE.request(uri).pipe(BASE.FS.createWriteStream('images/'+filename)).on('close', callback);
console.log('images/'+filename);
var stats = BASE.FS.statSync('images/'+filename);
var fileSizeInBytes = stats["size"];
console.log(fileSizeInBytes);
//Convert the file size to megabytes (optional)
var fileSizeInMegabytes = fileSizeInBytes/1000000.0;
console.log(fileSizeInMegabytes);
});
};
download('https://www.google.com/images/srpr/logo3w.png', 'google.png', function(){
console.log('done');
});
thnx stefan –