MulterS3 给出 this.client.send is not a function 错误

编程入门 行业动态 更新时间:2024-10-06 13:15:37

MulterS3 给出 this.client.send is not a function <a href=https://www.elefans.com/category/jswz/34/1771449.html style=错误"/>

MulterS3 给出 this.client.send is not a function 错误

注: 在 multer s3 中出现以下错误。这个错误指向 NPM 模块,我真的不明白这个模块的问题。我已经使用 upload.single 和 upload.array 方法来检查这个模块的工作。但不工作。

代码:

const bodyParser = require('body-parser');
const cors = require('cors');

const aws = require('aws-sdk');
const multer = require('multer');
const multerS3 = require('multer-s3');

const http = require('http');
const app = express();

app.set('port', 3000);
app.use(
  bodyParser.json({
    limit: '50mb'
  })
);
app.use(
  bodyParser.urlencoded({
    limit: '50mb',
    extended: true
  })
);
app.use(cors());

aws.config.update({
  accessKeyId: '',
  secretAccessKey: ''
});

s3 = new aws.S3();

const upload = multer({
  storage: multerS3({
    s3: s3,
    bucket: '',
    acl: 'public-read',
    contentType: multerS3.AUTO_CONTENT_TYPE,
    metadata: function (req, file, cb) {
      cb(null, {
        fieldName: file.fieldname
      });
    },
    key: function (req, file, cb) {
      let extArray = file.mimetype.split('/');
      let ext = extArray[extArray.length - 1];

      console.log(`ext ->> `, ext, ` file.fieldname ->> `, file.fieldname);

      cb(null, "test/" + Date.now().toString() + '.' + ext);
    },
    /* limits: {
      fileSize: 1024 * 1024 * 10
    } */
  })
});

(() => {
  server = http.createServer(app).listen(app.get('port'), () => {
    console.debug(`Server started ->> `);
    app.get('/test', (req, res) => {Mul
      res.send('Hello');
    });

    app.post('/media', upload.single('media'), (req, res) => {
      console.log(`req.files ->> `, req.file);
      res.send('Thanks for you waiting time');
    });
  });
})();

错误:

ext ->>  jpeg  file.fieldname ->>  media
TypeError: this.client.send is not a function
    at Upload.__uploadUsingPut (/home/tristate/Jay/Force/node_modules/@aws-sdk/lib-storage/dist-cjs/Upload.js:52:25)
    at Upload.__doConcurrentUpload (/home/tristate/Jay/Force/node_modules/@aws-sdk/lib-storage/dist-cjs/Upload.js:99:39)
    at process._tickCallback (internal/process/next_tick.js:68:7)

使用 multer-s3 寻找解决方案。提前谢谢你。

回答如下:

你检查过这个问题了吗? https://github/anacronw/multer-s3/issues/169

请检查您的aws-sdk,multer-s3版本是否兼容

更多推荐

MulterS3 给出 this.client.send is not a function 错误

本文发布于:2024-05-13 14:52:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1759735.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   client   function   send

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!