【发布时间】:2021-05-20 18:28:29
【问题描述】:
我正在尝试下载存储在 Expo React Native 应用程序的 Amazon Web Services S3 存储桶中的图像。我会包含我用来执行此操作的文档,但我不得不使用大量不同文档的合并,以至于我无法找到所有文档。
我相信我在这里拥有所有正确的信息,并且代码看起来应该对我有用,但我收到一个未处理的承诺拒绝说 [Unhandled promise rejection: CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1] 我将在下面发布完整的消息。
这就是我现在正在尝试的(我已经替换了身份池、访问密钥和密钥,但我确信它们都是正确的,因为我正在使用访问和密钥将图像上传到应用程序):
AWS.config.update({region: 'us-east-2'});
AWS.config.credentials = new AWS.CognitoIdentityCredentials({ IdentityPoolId: "MY-IDENTITY-POOL" }) //No idea if this is right
const s3 = new AWS.S3({
region: 'us-east-2',
credentials: {accessKey: 'MY-ACCESS-KEY', secretKey: 'MY-SECRET-KEY',},
params: {Bucket: 'rn-mobile-app-bucket'}
});
async function downloadFromS3 () {
const file = await s3.getObject({ Bucket: 'rn-mobile-app-bucket', Key: 'Uploaded Photos/ColePic' }).promise();
console.log(file);
return {
data: file.Body,
mimetype: file.ContentType
}
}
然后我在 useEffect 中调用该函数:
//Fetch all users from database
useEffect(() =>{
downloadFromS3();
fetch('http://10.0.2.2:5000/forms').then(response =>{
if(response.ok){
return response.json();
}
}).then(data => setFormsArray(data));
}, []);
您可以忽略该 fetch 方法,它工作正常且几乎不相关,但我不想省略代码。
我在这里遗漏了什么或者我做错了什么?
【问题讨论】:
标签: amazon-web-services react-native amazon-s3 expo