forked from mahrukhijaz/FYP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UploadCv.js
143 lines (136 loc) · 4.88 KB
/
UploadCv.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import React,{Component} from'react'
import {StyleSheet,Text,View,TouchableOpacity,KeyboardAvoidingView,StatusBar,Image}from 'react-native'
import {widthPercentageToDP as wp, heightPercentageToDP as hp} from 'react-native-responsive-screen'
import { Container } from 'native-base'
import DocumentPicker from 'react-native-document-picker';
import FileViewer from 'react-native-file-viewer';
export default class UploadCv extends Component{
state={FileSource:null}
constructor(props) {
super(props);
//Initialization of the state to store the selected file related attribute
this.state = {
singleFile: '',
};
}
async selectOneFile() {
//Opening Document Picker for selection of one file
try {
const res = await DocumentPicker.pick({
type: [DocumentPicker.types.pdf],
});
//Setting the state to show single file attributes
this.setState({
FileSource:res.uri,
singleFile: res });
FileViewer.open(res.uri)
} catch (err) {
//Handling any exception (If any)
if (DocumentPicker.isCancel(err)) {
//If user canceled the document selection
alert('Canceled from single doc picker');
} else {
//For Unknown Error
alert('Unknown Error: ' + JSON.stringify(err));
throw err;
}
}
}
async ShowFile() {
//Opening Document Picker for selection of one file
try {
const res = await DocumentPicker.show({
type: [DocumentPicker.types.allFiles],
});
//Setting the state to show single file attributes
this.setState({
FileSource:res.uri,
singleFile: res });
} catch (err) {
//Handling any exception (If any)
if (DocumentPicker.isCancel(err)) {
//If user canceled the document selection
alert('Canceled from single doc picker');
} else {
//For Unknown Error
alert('Unknown Error: ' + JSON.stringify(err));
throw err;
}
}
}
render(){
return(
<Container style={styles.container}>
<KeyboardAvoidingView>
<StatusBar backgroundColor="#0f1654" barStyle="light-content" />
<View>
<Text style={styles.MainText}>Hello World</Text>
<TouchableOpacity
style={styles.UploadBtn}
onPress={this.selectOneFile.bind(this)}>
<Text style={styles.BtnText}>Click Me To Upload File</Text>
</TouchableOpacity>
{/*Showing the data of selected Single file*/}
<Text style={styles.textStyle}>
File Name:{' '}
{this.state.singleFile.name ? this.state.singleFile.name : ''}
{'\n'}
Type: {this.state.singleFile.type ? this.state.singleFile.type : ''}
{'\n'}
File Size:{' '}
{this.state.singleFile.size ? this.state.singleFile.size : ''}
{'\n'}
URI: {this.state.singleFile.uri ? this.state.singleFile.uri : ''}
{'\n'}
</Text>
<View style={{ backgroundColor: 'grey', height: 2, margin: 10 }} />
<View>
{
this.state.FileSource && <Image source={{uri:this.state.FileSource}} style={{width:250,height:250,marginLeft:-10,justifyContent:'center',alignSelf:'center',borderWidth:4,borderColor:'white' }}/>
}
</View>
</View>
</KeyboardAvoidingView>
</Container>
)
}
}
const styles=StyleSheet.create({
container: {
height:hp('100%'),
width:wp('100%'),
justifyContent:'center',
alignItems:'center',
},
MainText: {
fontSize: 20,
fontWeight: 'bold',
justifyContent:'center',
alignSelf:'center',
},
UploadBtn: {
height:hp('8%'),
width:wp('80%'),
borderRadius:20,
backgroundColor:'blue',
justifyContent:'center',
alignSelf:'center',
},
BtnText: {
color:'white',
fontWeight:'bold',
fontSize:15,
alignSelf:'center',
},
imageIconStyle: {
height: 20,
width: 20,
resizeMode: 'stretch',
},
textStyle: {
backgroundColor: '#fff',
fontSize: 15,
marginTop: 16,
color: 'black',
},
})