我用expo init启动了一个名为MyVideoApp的裸露世博会应用程序。然后我创建了一个AWS帐户,并在终端中运行:
npm install -g @aws-amplify/cliamplify configure这将我签名到控制台,我完成了默认步骤,并在region:eu-west-2,username:amplify-user中创建了一个帐户,粘贴在accessKeyId & secretAccessKey,profile name:amplify-user-profile中。
cd ~/Documents/MyVideoApp/ & amplify init? Enter a name for the project MyVideoApp
? Enter a name for the environment dev
? Choose your default editor: IntelliJ IDEA
? Choose the type of app that you're building javascript
Please tell us about your project
? What javascript framework are you using react-native
? Source Directory Path: /
? Distribution Directory Path: /
? Build Command: npm run-script build
? Start Command: npm run-script start
Using default provider awscloudformation
? Do you want to use an AWS profile? Yes
? Please choose the profile you want to use amplify-user-profile
Adding backend environment dev to AWS Amplify Console app: d37chh30hholq6amplify push此时,我在我的项目目录中有一个amplify文件夹和一个名为amplify-myvideoapp-dev-50540-deployment的S3桶。我上传了一个图片到桶icon_1.png中。并试图通过点击按钮从应用程序下载。
import React from 'react';
import { StyleSheet, Text, View, SafeAreaView, Button } from 'react-native';
import Amplify, { Storage } from 'aws-amplify';
import awsmobile from "./aws-exports";
Amplify.configure(awsmobile);
async function getImage() {
try {
let data = await Storage.get('icon_1.jpg')
} catch (err) {
console.log(err)
}
}
export default function App() {
return (
<SafeAreaView style={styles.container}>
<Text>Hello, World!</Text>
<Button title={"Click to Download!"} onPress={getImage}/>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});输出:
No credentials
[WARN] 18:54.93 AWSS3Provider - ensure credentials error, No Cognito Identity pool provided for unauthenticated access
...所以我设置了(但可能不正确?)用户池(my_first_pool)和标识池(myvidapp)。这没什么用。此外,当我进入我的桶并单击权限->桶策略时,它只是空的.不确定是否可以,如果只有所有者尝试访问桶&它的内容。
我不知道出了什么问题,还想试试什么。实际上,我只想验证我的后端,以便任何git clone代码的人都能够运行它并访问存储桶。
编辑:aws-exports.js
/* eslint-disable */
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.
const awsmobile = {
"aws_project_region": "eu-west-2"
};
export default awsmobile;发布于 2020-10-12 20:38:05
由于您已经表示可以公开访问S3桶中的所有文件,所以我建议如下:
在AWS控制台(console.aws.amazon.com)中选择桶的
。
{“版本”:"2012-10-17",“声明”:[{ "Sid":"PublicRead",“效果”:“允许”,“主体”:"*",“行动”:"s3:GetObject","s3:GetObjectVersion“,"Resource":[“arn:aws:s3:YOUR_BUCKET_NAME_HERE/*”}] }
https://stackoverflow.com/questions/64324533
复制相似问题