小编Erw*_*iou的帖子

AWS S3 Bucket - getSignedUrl PUT 返回 400(错误请求)

我在我的项目中遇到了一个奇怪的问题,我无法找到我做错了什么。我正在尝试将图像上传到我的博客,并且我正在使用 aws s3 配置来执行此操作。我相信我的配置是正确的,但以防万一我会在那里添加它们:

这是我的 cors 配置

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
<CORSRule>
    <AllowedOrigin>http://localhost:3000</AllowedOrigin>
    <AllowedMethod>PUT</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Run Code Online (Sandbox Code Playgroud)

我所有的 IAM 策略和用户 api 都井井有条并已激活。这是我后端的代码:

const s3 = new AWS.S3({
  accessKeyId: keys.aws.clientID,
  secretAccessKey: keys.aws.clientSecret,
  signatureVersion: "v4",
  region: "eu-west-3"
})

const router = express.Router()
// @route  GET api/posts/upload
// @desc   Upload an image on amazone server API
// @access Private
router.get(
  "/upload",
  passport.authenticate("jwt", { session: false }),
  (req, res) => {
    const key = `${req.user.id}/${uuid()}.jpeg`
    s3.getSignedUrl( …
Run Code Online (Sandbox Code Playgroud)

amazon-s3 amazon-web-services node.js jwt redux

3
推荐指数
1
解决办法
2828
查看次数

标签 统计

amazon-s3 ×1

amazon-web-services ×1

jwt ×1

node.js ×1

redux ×1