大家好! 我是 React Native 的新手。我正在学习它,但我在使用 expo 文档选择器时遇到了问题。我使用文档选择器,但它没有显示任何显示或有时给出承诺拒绝错误。 我今天坚持了很长时间。
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
我想上传一个文件。
答案 0 :(得分:1)
首先安装https://www.tensorflow.org/api_docs/python/tf/gradients
其次,您的导入声明是错误的
你写的第三行
import * as DocumentPicker from 'expo';
但你必须写 import * as DocumentPicker from 'expo-document-picker';
我已经改正了。检查一次。
import React, {useState} from 'react';
import { StyleSheet, Text, View, TextInput, Button, TouchableOpacity } from 'react-native';
import * as DocumentPicker from 'expo-document-picker';
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