Unable to read file returned from `DocumentPicker`
See original GitHub issueEnvironment
Environment:
OS: macOS Sierra 10.12.6
Node: 9.10.1
Yarn: 1.5.1
npm: 3.10.10
Watchman: 4.7.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: 3.0 AI-171.4443003
Packages: (wanted => installed)
expo: ^26.0.0 => 26.0.0
react: 16.3.0-alpha.1 => 16.3.0-alpha.1
react-native: https://github.com/expo/react-native/archive/sdk-26.0.0.tar.gz => 0.54.2
Diagnostics report:
https://exp-xde-diagnostics.s3.amazonaws.com/riwu-1fee4770-788f-458d-9176-1739c4b5f9cc.tar.gz
Reproducible Demo
import React from 'react';
import { Button, View, Text } from 'react-native';
import { DocumentPicker, FileSystem } from 'expo';
class App extends React.Component {
state = {
data: null,
};
render() {
return (
<View style={{ flex: 1, justifyContent: 'center' }}>
<Button
title="Click"
onPress={async () => {
const result = await DocumentPicker.getDocumentAsync({
type: '*/*',
});
if (result.type === 'cancel') return;
console.log('uri', result.uri);
try {
const info = await FileSystem.getInfoAsync(result.uri);
this.setState({ data: info });
console.warn('info', info);
const content = await FileSystem.readAsStringAsync(result.uri);
console.warn('content', content);
this.setState({ data: content });
} catch (e) {
this.setState({ data: e.message })
}
}}
/>
<Text>{JSON.stringify(this.state.data)}</Text>
</View>
);
}
}
export default App;
https://snack.expo.io/@riwu/documentpicker
I selected a plain text file.
On Android it fails at FileSystem.readAsStringAsync
with
Error: Unsupported scheme for location ‘content://com.android.providers.downloads.documents/document/19778’.]
On iOS it fails at FileSystem.getInfoAsync
with
Error: File ‘file:///private/var/mobile/Containers/Data/Application/86126CD3-95A3-4F10-ABD7-6EFE0772A9FC/tmp/host.exp.Exponent-Inbox/a.txt’ isn’t readable.]
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Reading file inside documentPicker returns nil - Stack Overflow
I found the issue and solved it. I should have used didPickDocumentAt instead of didPickDocumentsAt and then request access.
Read more >UIDocumentPicker Error on accession selected file
I'm testing on iPhone 11 with iOS 13.5.1. This is my implementation: Code Block. func documentPicker(_ controller: UIDocumentPickerViewController, ...
Read more >DocumentPicker - Expo Documentation
expo-document-picker provides access to the system's UI for selecting documents from the available providers on the user's device.
Read more >react-native-document-picker - npm
Use pickMultiple , pickSingle or pick to open a document picker for the user to select file(s). All methods return a Promise.
Read more >Document Picker in Xamarin.iOS - Microsoft Learn
This document describes the iOS Document Picker and discusses how to use ... ("Unable to Save Document"); successful=false; } }); // Return ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s not very obvious from the docs. Found the solution here: https://forums.expo.io/t/read-a-contents-from-dropbox-with-documentpicker-filesystem/1976/5
Essentially, we have to download the file first:
content://com.android.contacts/contacts/10720/photo how can access this from with expo. how can I read it with the file system? @aalices it is possible with Expo?