0

我在用户编辑个人资料页面上将图像上传到 s3,它可以工作,但是在图像保存在 s3 后,页面在保存更改后重新加载。

找不到图像,但是,如果我刷新它的页面,那里...

任何想法可能是什么问题?

这在控制器中应用:

exports.resize = async (req, res, next) => {
  // check if there is no new file to resize
  if (!req.file) {
    next(); // skip to the next middlewaree
    return;
  }
  const extension = req.file.mimetype.split('/')[1]
  req.body.photo = `${uuid.v4()}.${extension}`

  let readyimg
  const imageAws = await sharp(req.file.buffer)
    .resize(800, 800)
    .toBuffer()
    .then( data => {
      readyimg = data
    })

  AWS.config.update({
    secretAccessKey: process.env.SECRETACCESSKEY,
    accessKeyId: process.env.ACCESSKEYID,
    region: 'us-east-1'
  })

  const s3 = new AWS.S3()

  const params = {
    Bucket: 'jamsession-images',
    Key: req.body.photo,
    Body: readyimg
  };

  await s3.upload(params, function (err, data) {
    if (err) {
      console.log('%%%%%%%%%%%%%%% error in callback');
      console.log(err);
    }
    console.log('****************** success');
    console.log(data);
  });

  next()
};
4

1 回答 1

0

它自己修复了......我猜aws存储桶需要先获得几个请求才能使用?

于 2019-05-23T20:54:38.600 回答