小编J. *_*ake的帖子

使用 aws-amplify for 节点的存储 (S3) 时出现“无凭据”错误

当尝试从 S3 中的存储桶获取图像时,I\xc2\xb4m 收到错误“无凭据”:

\n\n

\r\n
\r\n
import React, { Component } from \'react\'\r\nimport { Auth, Storage } from \'aws-amplify\'\r\n\r\n\r\ncomponentDidMount(){\r\n\r\nStorage.get(\'random-image.jpg\')\r\n                .then(data => {\r\n                    console.log(data)\r\n                }).catch(err => console.log(err))\r\n         \r\n}
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n\n

对于我\xc2\xb4听说的我需要添加一个身份联合池,我\xc2\xb4m努力理解aws-amplify和aws-sdk之间的区别,特别是我必须在我的应用程序中放置身份的确切位置联合池 url 才能使其正常工作。

\n\n

Here\xc2\xb4s是我到目前为止的代码,我\xc2\xb4m使用cognito服务来允许用户注册和登录,并使用S3让用户能够上传图像。

\n\n

\r\n
\r\n
Amplify.configure({\r\n    Auth: {\r\n        mandatorySignId: true,\r\n        region: config.cognito.REGION,\r\n        userPoolId: config.cognito.USER_POOL_ID,\r\n        userPoolWebClientId: config.cognito.APP_CLIENT_ID\r\n    },\r\n    Storage: {\r\n        AWSS3: {\r\n            bucket: config.s3.bucket,\r\n            region: config.s3.region, \r\n        }\r\n    }\r\n})
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n\n

但是现在我需要实现必要的代码,以便能够对 S3 存储桶执行 GET 请求,并且从 i\xc2\xb4ve 读取的内容中,我需要打开一个与我的认知用户池相关的联合身份池,然后将此代码粘贴到应用程序中:

\n\n

\r\n
\r\n
AWS.config.region = \'eu-west-2\'; …
Run Code Online (Sandbox Code Playgroud)

javascript amazon-s3 amazon-web-services node.js reactjs

6
推荐指数
0
解决办法
1529
查看次数