Skip to content

Instantly share code, notes, and snippets.

@dabit3
Created March 5, 2018 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dabit3/33b5c3c6fa9bf92b1291e34a30022cf5 to your computer and use it in GitHub Desktop.
Save dabit3/33b5c3c6fa9bf92b1291e34a30022cf5 to your computer and use it in GitHub Desktop.
Amplify S3 example
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