繁体   English   中英

(nodejs)如何在上传multIpart时同时上传S3和GCS

[英](nodejs) how to upload both S3 and GCS together when uploading multIpart

我正在创建一个可以上传s3和gcs的nodejs express程序。

在我的代码中,“ / uploadAll”不起作用。

仅上传到s3,而不上传到gcs。

我尝试了Googleing,但找不到它。

如何上传所有这些?

期待您的回复...谢谢!

const express = require('express');
const bodyParser = require('body-parser');
const multer = require('multer');
const awsSDK = require('aws-sdk');
const s3 = new awsSDK.S3();
const multerS3 = require('multer-s3');
const multerGoogleStorage = require("multer-google-storage");
const app = express();

app.use(bodyParser.json());

const gcsMulter = multer({
    storage: multerGoogleStorage.storageEngine({
        keyFilename: '../key.json',
        bucket: 'test-bucket',
        projectId: 'TestProject',
        filename: function (req, file, cb) {
            cb(null, `test/_${file.originalname}`);
        }
    })
});

const s3Multer = multer({
    storage: multerS3({
        s3: s3,
        bucket: 'test-bucket',
        acl: 'public-read',
        key: function (req, file, cb) {
            cb(null, `test/_${file.originalname}`);
        }
    })
});

const s3Upload = s3Multer.fields([{
    name: 'images'
}, {
    name: 'thumbs'
}]);

const gcsUpload = gcsMulter.fields([{
    name: 'images'
}, {
    name: 'thumbs'
}]);

app.post('/uploadS3', s3Upload, (req, res, next) => {
    res.json(req.files);
});

app.post('/uploadGCS', gcsUpload, (req, res, next) => {
    res.json(req.files);
});

app.post('/uploadAll', s3Upload, gcsUpload, (req, res, next) => {
    res.json(req.files); 
});

const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
    console.log(`App listening on port ${PORT}`);
    console.log('Press Ctrl+C to quit.');
});

GCS当前不支持分段上传。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM