最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

网站源码admin43浏览0评论

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

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版本是否兼容

发布评论

评论列表(0)

  1. 暂无评论