gpt4 book ai didi

javascript - expo 文档选择器未显示上传文件

转载 作者:行者123 更新时间:2023-12-02 02:17:19 25 4
gpt4 key购买 nike

我是 React Native 的新手。我正在学习它,但我在处理 expo 文档选择器 时遇到了问题。我使用文档选择器,但它不显示任何内容或有时会出现 promise 拒绝错误。今天卡了好久。

上传.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;

我要上传文件。

最佳答案

首先安装expo-document-picker

其次,你的导入语句是错误的

在你写的第三行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 = () => {
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;

关于javascript - expo 文档选择器未显示上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66967900/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com