我使用api sails和mongo来存储图像,side front nodeJs 我想下载X图像,只需一张图片,代码在功能上:
db.open(function (){
gfs.exist({ _id: id }, function(err, found) {
if (err) {
return err.negotiate(err);
}
if (!found) {
return res.negotiate('No file found');
}
gfs.createReadStream({ _id: id }).pipe(res);
});
});
下载x图片......没有想法......
感谢您的帮助
答案 0 :(得分:1)
i am doing it by using this
if (fileExists(image_name) == false) { //check the file exist or not
var file = fs.createWriteStream( image_name);
http.get(url, function (response) {
response.pipe(file);
})else{
console.log('already exist.');
}
});
希望这会有所帮助。