I am trying to download an image that I have stored in an Amazon Web Services S3 Bucket in an Expo React Native application. I would include the documentation that I have used to do this but I have had to use such a large amalgamation of different docs that I can't locate them all.
I believe that I have all the correct info here and the code looks like it should work to me, but I am getting an unhandled promise rejection saying [Unhandled promise rejection: CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1] I will post the full message below.
This is what I am trying right now (I have substituted the identity pool, access key, and secret key but I am certain that they are all correct as I am using the access and secret key to upload the images elsewhere in the app):
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
}
}
And then I call the function in a 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));
}, []);
You can ignore that fetch method it works fine and is mostly unrelated but I didn't want to omit code.
What am I missing here or what am I doing wrong?