I'm new in react native. I'm learning it but I'm facing an issue working on expo document picker
. I use the document picker, but it does not display anything showing or sometimes gives a promise rejection error.
I'm stuck at it for a long time today.
upload.js
import React, { useState } from "react";
import {
StyleSheet,
Text,
View,
TextInput,
Button,
TouchableOpacity,
} from "react-native";
import * as DocumentPicker from "expo";
const UploadFile = () => {
pickDocument = async () => {
let result = await DocumentPicker.getDocumentAsync({});
console.log(result.uri);
console.log(result);
};
return (
<View style={styles.background}>
<Text style={styles.file}>Upload CSV File</Text>
<View style={styles.button}>
<TouchableOpacity>
<Button
title="upload your file"
color="black"
onPress={pickDocument}
/>
</TouchableOpacity>
</View>
</View>
);
};
const styles = StyleSheet.create({
background: {
backgroundColor:
"radial-gradient(ellipse at left bottom, rgb(163, 237, 255) 0%, rgba(57, 232, 255, 0.9) 59%, rgba(48, 223, 214, 0.9) 100% )",
},
file: {
color: "black",
marginHorizontal: 145,
},
button: {
marginHorizontal: 60,
},
});
export default UploadFile;
I want to upload a file.
I'm new in react native. I'm learning it but I'm facing an issue working on expo document picker
. I use the document picker, but it does not display anything showing or sometimes gives a promise rejection error.
I'm stuck at it for a long time today.
upload.js
import React, { useState } from "react";
import {
StyleSheet,
Text,
View,
TextInput,
Button,
TouchableOpacity,
} from "react-native";
import * as DocumentPicker from "expo";
const UploadFile = () => {
pickDocument = async () => {
let result = await DocumentPicker.getDocumentAsync({});
console.log(result.uri);
console.log(result);
};
return (
<View style={styles.background}>
<Text style={styles.file}>Upload CSV File</Text>
<View style={styles.button}>
<TouchableOpacity>
<Button
title="upload your file"
color="black"
onPress={pickDocument}
/>
</TouchableOpacity>
</View>
</View>
);
};
const styles = StyleSheet.create({
background: {
backgroundColor:
"radial-gradient(ellipse at left bottom, rgb(163, 237, 255) 0%, rgba(57, 232, 255, 0.9) 59%, rgba(48, 223, 214, 0.9) 100% )",
},
file: {
color: "black",
marginHorizontal: 145,
},
button: {
marginHorizontal: 60,
},
});
export default UploadFile;
I want to upload a file.
Share Improve this question edited Aug 5, 2021 at 17:44 Kartikey 5,0024 gold badges18 silver badges43 bronze badges asked Apr 6, 2021 at 11:37 Adil IjazAdil Ijaz 3521 gold badge5 silver badges27 bronze badges1 Answer
Reset to default 7Firstly install expo-document-picker
Secondly, Your Import Statement is wrong
On the third line you wrote
import * as DocumentPicker from 'expo';
but you have to write import * as DocumentPicker from 'expo-document-picker';
I have corrected it. Check once.
import React, { useState } from "react";
import {
StyleSheet,
Text,
View,
TextInput,
Button,
TouchableOpacity,
} from "react-native";
import * as DocumentPicker from "expo-document-picker";
const UploadFile = () => {
const pickDocument = async () => {
let result = await DocumentPicker.getDocumentAsync({});
console.log(result.uri);
console.log(result);
};
return (
<View style={styles.background}>
<Text style={styles.file}>Upload CSV File</Text>
<View style={styles.button}>
<TouchableOpacity>
<Button
title="upload your file"
color="black"
onPress={pickDocument}
/>
</TouchableOpacity>
</View>
</View>
);
};
const styles = StyleSheet.create({
background: {
backgroundColor:
"radial-gradient(ellipse at left bottom, rgb(163, 237, 255) 0%, rgba(57, 232, 255, 0.9) 59%, rgba(48, 223, 214, 0.9) 100% )",
},
file: {
color: "black",
marginHorizontal: 145,
},
button: {
marginHorizontal: 60,
},
});
export default UploadFile;