Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, {Component} from 'react';
- import { View,Text, Image, StyleSheet,Button, Platform} from 'react-native';
- import firebase from './src/FirebaseCon';
- import ImagePicker from 'react-native-image-picker';
- import RNFetchBlob from 'react-native-fetch-blob';
- //console.disableYellowBox = true;
- window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest;
- window.Blob = RNFetchBlob.polyfill.Blob;
- export default class PrimeiroProjeto extends Component{
- constructor(props){
- super(props);
- this.state = {
- foto:null
- };
- this.pegarFoto = this.pegarFoto.bind(this);
- }
- pegarFoto(){
- ImagePicker.launchImageLibrary({}, (r)=>{
- if(r.uri){
- let uri = r.uri.replace('file://', '');
- let imagem = firebase.storage().ref().child('images').child('imagem.jpg');
- let mime = 'image/jpeg';
- RNFetchBlob.fs.readFile(uri, 'base64')
- .then((data)=>{
- return RNFetchBlob.polyfill.Blob,build(data, {type:mime+';BASE64'});
- })
- .then((blob)=>{
- imagem.put(blob, {contentType:mime})
- .then(()=>{
- blob.close();
- alert("Terminou o processo");
- let url = imagem.getDownloadURL();
- })
- .catch((error)=>{
- alert(error.code);
- });
- });
- }
- });
- }
- render(){
- return (
- <View style={styles.container}>
- <Button title="Pegar foto" onPress={this.pegarFoto} />
- <Image style={styles.foto} source={this.state.foto} />
- </View>
- );
- }
- }
- const styles = StyleSheet.create({
- container:{
- flex:1,
- marginTop:10
- },
- foto:{
- height:300,
- width:300
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement