Created
March 5, 2018 17:26
-
-
Save dabit3/33b5c3c6fa9bf92b1291e34a30022cf5 to your computer and use it in GitHub Desktop.
Amplify S3 example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { | |
StyleSheet, | |
Text, | |
Button, | |
View, | |
Image | |
} from 'react-native'; | |
import Amplify, { Storage } from 'aws-amplify' | |
import config from './aws-exports' | |
Amplify.configure(config) | |
// window.LOG_LEVEL='DEBUG' | |
export default class App extends Component { | |
state = { | |
url: '' | |
} | |
async getFile() { | |
let name = 'example-image.png'; | |
let fileUrl = await Storage.get(name); | |
this.setState({ | |
url: fileUrl | |
}) | |
} | |
render() { | |
return ( | |
<View style={styles.container}> | |
<Text>Storage</Text> | |
<Button | |
title="Get Image" | |
onPress={this.getFile.bind(this)} | |
/> | |
{ | |
this.state.url !== '' && ( | |
<Image | |
source={{ uri: this.state.url }} | |
style={{ width: 300, height: 300 }} | |
/> | |
) | |
} | |
</View> | |
); | |
} | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
justifyContent: 'center', | |
alignItems: 'center' | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment