0
我正在寻找一种在发送到云(openstack,s3或其他)之前调整图像大小(通过标准html表单提交上传)的方法。NodeJS + Multer + PkgCloud:在将图像发送到云之前调整图像大小
我使用NodeJS和3个插件:Multer(上传管理),lwip(图像调整大小)和PkgCloud(转移到云)。
我可以用multer处理上传,我可以用lwip在服务器上写一个新的调整大小的文件。
var fs = require('fs'),
multer = require('multer'),
upload = multer({ dest: 'uploads/medias/' }),
pkgcloud = require('pkgcloud'),
client = pkgcloud.storage.createClient({/* some config */});
// "router" is an instance of a route from Express
router.post('/media/:id/image', upload.single('file'), function (req) {
var lwip = require('lwip'),
type = 'png',
npath = req.file.path + '_150x150';
// the file exists and the log shows information
console.log(req.file);
// open image
lwip.open(req.file.path, type, function (err, image) {
image.batch()
.resize(150, 150)
.writeFile(npath, type, function() {
// remove raw file
fs.unlink(req.file.path, function() {
// how do I send the new resized file to the pkgcloud client?
});
});
});
});
但我错过了一些东西,而且我找不到将这个新文件发送到云端的方法。我发现了一个管理multer和配置的pkgcloud实例(multer-storage-pkgcloud)之间转移的插件,但我无法弄清楚如何在将文件发送到云之前调整其大小。
有没有人有一个想法如何处理?
感谢