Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js NodeJS+;Multer&x2B;PkgCloud:在将图像发送到云之前调整图像大小_Node.js_Multer_Pkgcloud - Fatal编程技术网

Node.js NodeJS+;Multer&x2B;PkgCloud:在将图像发送到云之前调整图像大小

Node.js NodeJS+;Multer&x2B;PkgCloud:在将图像发送到云之前调整图像大小,node.js,multer,pkgcloud,Node.js,Multer,Pkgcloud,我正在寻找一种在将图像发送到云(openstack、s3或其他)之前调整图像大小的方法(通过标准html表单提交上传) 我正在使用NodeJS和3个插件:Multer(上传管理)、lwip(图像大小调整)和PkgCloud(传输到云) 我可以用multer处理上传,我可以用lwip在服务器上写一个新的调整大小的文件 var fs = require('fs'), multer = require('multer'), upload = multer({ dest: 'uploa

我正在寻找一种在将图像发送到云(openstack、s3或其他)之前调整图像大小的方法(通过标准html表单提交上传)

我正在使用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)之间的传输,但在将文件发送到云之前,我不知道如何调整文件大小

有人知道怎么处理吗


谢谢

我找到了一种方法,只需从文件中创建一个流,并使用pkgcloud实例对其进行管道传输:

var fstream = fs.createReadStream(path_to_file);
fstream.pipe(client.upload({
    container: 'container-id',
    remote: 'remote-name'
});
此代码中缺少:所有成功和错误回调。但想法就在这里