![](/img/trans.png)
[英]How to upload react-native image from expo-image-picker to Express.js server using multer
[英]My react native app keeps crashing when selecting an image with expo-image-picker
const Sell = ({navigation}) => { // sell page, user will be able to sell their OWNED foods.
let [visible, setVisible] = useState(false);
const [image, setImage] = useState(null);
const toggleOverlay = () => {
setVisible(!visible);
}
let openImagePickerAsync = async () => {
let permissionResult = await ImagePicker.requestMediaLibraryPermissionsAsync();
if (permissionResult.granted === false) {
alert("Permission to access camera roll is required!");
return;
}
let pickerResult = await ImagePicker.launchImageLibraryAsync();
if(pickerResult.cancelled === true) {
return;
}
setImage({localUri: pickerResult.uri});
}
if(image !== null) {
return (
<Image source={{uri: image.localUri}}/>
);
}
return(
<View style={styles.yourProfileContent}>
<Overlay isVisible={visible} onBackdropPress={toggleOverlay} fullScreen={true}>
<View style={styles.yourProfileChangePassword}>
<TouchableOpacity style={{padding: 5}} onPress={openImagePickerAsync}>
{image && <Image source={{ uri: image }} style={{ width: 200, height: 200 }} />}
<MaterialCommunityIcons name='camera' size={50} color='#ff66ff'/>
</TouchableOpacity>
<View style={{flexDirection: 'row'}}>
<MaterialCommunityIcons name='pencil' size={20} color='#ff66ff' style={styles.sellIcons}/>
<TextInput maxLength={20} style={styles.textInput} placeholder='Title' placeholderTextColor='#ff66ff' maxLength={20}/>
</View>
<View style={{flexDirection: 'row'}}>
<MaterialCommunityIcons name='cash' size={20} color='#ff66ff' style={styles.sellIcons}/>
<TextInput style={styles.textInput} placeholderTextColor='#ff66ff' placeholder="Price (dollars)"
/>
</View>
<View style={{flexDirection: 'row'}}>
<MaterialCommunityIcons name='book' size={20} color='#ff66ff' style={styles.sellIcons}/>
<TextInput style={styles.textInput} placeholderTextColor='#ff66ff' placeholder="Description" maxLength={200} multiline={true}
/>
</View>
<Button color='#ff66ff' title="POST"/>
<Text style={styles.register} onPress={toggleOverlay}>Go back.</Text>
</View>
</Overlay>
<Text style={{textAlign: 'center', fontSize: 20, fontWeight:'bold', marginBottom: 5, color: '#ff66ff'}}>Create new listing</Text>
<TouchableOpacity style={styles.addListing} onPress={toggleOverlay}>
<Text style={{color: 'white'}}>+</Text>
</TouchableOpacity>
</View>
);
}
我讀到 expo 托管反應本機應用程序無權訪問 androidmanifest.xml 文件以允許相機選擇器的權限,但我使用 expo-image-picker 表示在托管應用程序中,從相機中選擇圖像的權限(權限。 CAMERA) 或相機膠卷 (Permissions.MEDIA_LIBRARY) 會自動添加。 我的應用程序仍然崩潰,有時會拋出錯誤: Lateinit 屬性條帶尚未初始化。 我無權訪問 android 文件,因為它是一個 expo 托管項目。 我很困。
此錯誤與我們對 Android 上 Expo Go 的最新更新有關
ExpoGo 應用程序的新版本也已發布。
將您的 expo go 應用程序更新為Expo Go 2.19.6
.
在這里閱讀完整的報道
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.