【问题标题】:AWS S3 Image Uploader with NodeJS and s3-uploader module使用 Node JS 和 s3-uploader 模块上传 AWS S3 图像
【发布时间】:2017-09-04 06:47:02
【问题描述】:

我正在尝试使用此模块https://www.npmjs.com/package/s3-uploader,但对我来说尚不清楚如何实现它。如何对我的路由器进行POST

.post('/upload', ensureAuthenticated, (req, res, next) => {

let files = req.files;

let client = new Upload(process.env.AWS_BUCKET_NAME, {
  aws: {
    path: process.env.AWS_BUCKET_PATH,
    region: process.env.AWS_BUCKET_REGION,
    acl: 'public-read'
  },

  cleanup: {
    versions: true,
    original: false
  },

  original: {
    awsImageAcl: 'private'
  },

  versions: [{
    maxHeight: 1040,
    maxWidth: 1040,
    format: 'jpg',
    suffix: '-large',
    quality: 80,
    awsImageExpires: 31536000,
    awsImageMaxAge: 31536000
  },{
    maxWidth: 780,
    aspect: '3:2!h',
    suffix: '-medium'
  },{
    maxWidth: 320,
    aspect: '16:9!h',
    suffix: '-small'
  },{
    maxHeight: 100,
    aspect: '1:1',
    format: 'png',
    suffix: '-thumb1'
  },{
    maxHeight: 250,
    maxWidth: 250,
    aspect: '1:1',
    suffix: '-thumb2'
  }]
});

client.upload(files.file.path, {}, function(err, versions, meta) {
  if (err) { throw err; }

  versions.forEach(function(image) {
    console.log(image.width, image.height, image.url);
    // 1024 760 https://my-bucket.s3.amazonaws.com/path/110ec58a-a0f2-4ac4-8393-c866d813b8d1.jpg
  });
});
}

.post 中,我复制并粘贴了他们在 NPM 网站中的代码,并将变量值更改为我的值。

我收到此错误:

Error: Command failed: identify -format "name=
size=%[size]
format=%m
colorspace=%[colorspace]
height=%[height]
width=%[width]
orientation=%[orientation]
" /images/logo.png
/bin/sh: identify: command not found

    at ChildProcess.exithandler (child_process.js:206:12)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:877:16)
    at Socket.<anonymous> (internal/child_process.js:334:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:498:12)

我在此线程中发现了一个相关但不完全有用的主题: Node.js S3-uploader issue

【问题讨论】:

    标签: node.js express amazon-s3 npm


    【解决方案1】:

    解决方法如下:

    我唯一做的就是在我的本地主机上安装 imagemagick。

    您必须在终端中运行它。

    cd $HOME

    brew install imagemagick

    完成后,您可以运行它来查看版本和详细信息

    brew info imagemagick

    如果你没有brew,那么你需要安装它。

    谢谢

    【讨论】:

      猜你喜欢
      • 2015-01-12
      • 2019-09-09
      • 2017-10-17
      • 2016-10-13
      • 1970-01-01
      • 2018-12-13
      • 1970-01-01
      • 2018-05-03
      • 2019-03-18
      相关资源
      最近更新 更多