showing results for - "react native document picker example"
Amelie
14 Feb 2019
1try {
2  const res = await DocumentPicker.pick({
3    type: [DocumentPicker.types.allFiles],
4    //There can me more options as well
5    // DocumentPicker.types.allFiles
6    // DocumentPicker.types.images
7    // DocumentPicker.types.plainText
8    // DocumentPicker.types.audio
9    // DocumentPicker.types.pdf
10  });
11  //Printing the log realted to the file
12  console.log('res : ' + JSON.stringify(res));
13  console.log('URI : ' + res.uri);
14  console.log('Type : ' + res.type);
15  console.log('File Name : ' + res.name);
16  console.log('File Size : ' + res.size);
17  //Setting the state to show single file attributes
18  this.setState({ singleFile: res });
19} catch (err) {
20  //Handling any exception (If any)
21  if (DocumentPicker.isCancel(err)) {
22    //If user canceled the document selection
23    alert('Canceled from single doc picker');
24  } else {
25    //For Unknown Error
26    alert('Unknown Error: ' + JSON.stringify(err));
27    throw err;
28  }
29}