使用nodeJS提高发送静态图像的速度

我有一个典型的客户端/服务器应用程序,我可以发送图像到服务器,我需要不同大小的客户端上的图像。

所以目前我使用的Andr oid毕加索加载图像,并与nodeJS我服务的图像作为静态文件,因为他们被保存在静态文件所在的文件夹。

我的问题是:有没有办法提高发送这个静态文件(只是图像)的速度,或者我可以减less他们的大小使用我目前的静态文件的代码?

app.use(express.static(path.join(__dirname, 'public'))); 

目前我从客户端以base64的forms接收图像,并在服务器上将其转换为像这样的位图:

var bitmap = new Buffer(req.body.base64,'base64');

并将该位图存储在我用作静态文件夹的公用文件夹中,因为这是不好的做法,所以我不直接将图像存储在数据库中,我只是保存path,每次我想要检索静态文件夹内的图像在哪儿。

所以每次在我的客户端,我想回顾一下照片我只需要知道什么是静态path,没有更多。

为了更好的理解,我在这里留下了我的控制器的代码,我保存的照片。

调节器

 sendPicture: function (req, res, next) { var plant = null if (req.params.id != 0) { plant = req.params.id; } var bitmap = new Buffer(req.body.base64, 'base64'); var lat = req.body.lat; var lon = req.body.lon; var alt = req.body.alt; var date = req.body.date; var flowerName; var pathId = shortid.generate(); var userId = req.userId; if (plant != null) { Plant.findOne({ where: { id: req.params.id } }).then(function (plant) { if (!plant) { return 'not found'; } flowerName = plant.specie; }).then(function () { var pathToSave = __dirname + "/../public/images/" + flowerName + "/" + pathId + req.params.id + "-" + userId + ".jpg"; var path = "images/" + flowerName + "/" + pathId + req.params.id + "-" + userId + ".jpg" fsPath.writeFile(pathToSave, bitmap, function (err) { if (err) { console.log(err.stack); return err; } Foto.create({ image: path, userId: userId, plantId: req.params.id, lat: req.body.lat, lon: req.body.lon, alt: req.body.alt, date: date, }).then(function () { return res.status(200).json({ message: "foto created" }); }).catch(function (err) { console.log(err.stack); }) }); }); }