Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. import React, {Component} from 'react';
  2. import { View,Text, Image, StyleSheet,Button, Platform} from 'react-native';
  3. import firebase from './src/FirebaseCon';
  4. import ImagePicker from 'react-native-image-picker';
  5. import RNFetchBlob from 'react-native-fetch-blob';
  6. //console.disableYellowBox = true;
  7.  
  8. window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest;
  9. window.Blob = RNFetchBlob.polyfill.Blob;
  10.  
  11.  
  12. export default class PrimeiroProjeto extends Component{
  13.  
  14. constructor(props){
  15. super(props);
  16. this.state = {
  17. foto:null
  18. };
  19.  
  20. this.pegarFoto = this.pegarFoto.bind(this);
  21.  
  22. }
  23.  
  24. pegarFoto(){
  25.  
  26. ImagePicker.launchImageLibrary({}, (r)=>{
  27. if(r.uri){
  28. let uri = r.uri.replace('file://', '');
  29. let imagem = firebase.storage().ref().child('images').child('imagem.jpg');
  30. let mime = 'image/jpeg';
  31.  
  32. RNFetchBlob.fs.readFile(uri, 'base64')
  33. .then((data)=>{
  34. return RNFetchBlob.polyfill.Blob,build(data, {type:mime+';BASE64'});
  35. })
  36. .then((blob)=>{
  37. imagem.put(blob, {contentType:mime})
  38. .then(()=>{
  39. blob.close();
  40. alert("Terminou o processo");
  41. let url = imagem.getDownloadURL();
  42. })
  43. .catch((error)=>{
  44. alert(error.code);
  45. });
  46. });
  47. }
  48. });
  49.  
  50. }
  51.  
  52.  
  53. render(){
  54.  
  55. return (
  56.  
  57. <View style={styles.container}>
  58. <Button title="Pegar foto" onPress={this.pegarFoto} />
  59. <Image style={styles.foto} source={this.state.foto} />
  60. </View>
  61.  
  62.  
  63. );
  64. }
  65.  
  66. }
  67.  
  68. const styles = StyleSheet.create({
  69. container:{
  70. flex:1,
  71. marginTop:10
  72. },
  73. foto:{
  74. height:300,
  75. width:300
  76. }
  77. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement