How to use the react-native-document-picker.pick function in react-native-document-picker

To help you get started, we’ve selected a few react-native-document-picker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github berty / berty / js / packages / components / onboarding / AccountSelector.tsx View on Github external
onPress={async () => {
						try {
							const res = await DocumentPicker.pick({
								// @ts-ignore
								type: ['public.tar-archive', '*/*'],
							})

							await importAccount(res.uri.replace(/^file:\/\//, ''))
						} catch (err) {
							if (DocumentPicker.isCancel(err)) {
								// ignore
							} else {
								console.error(err)
							}
						}
					}}
					icon={'upload-outline'}
github berty / berty / js / packages / components / onboarding / CreateAccount.js View on Github external
const onImportPress = async () => {
		try {
			const res = await DocumentPicker.pick({
				// @ts-ignore
				type: ['public.tar-archive', '*/*'],
			})

			await ctx.importAccount(res.uri.replace(/^file:\/\//, ''))
		} catch (err) {
			if (DocumentPicker.isCancel(err)) {
				// ignore
			} else {
				console.error(err)
			}
		}
	}
github berty / berty / js / packages / components / main / home / MultiAccount.tsx View on Github external
onPress={async () => {
						try {
							const res = await DocumentPicker.pick({
								// @ts-ignore
								type: ['public.tar-archive', '*/*'],
							})

							await importAccount(res.uri.replace(/^file:\/\//, ''))
						} catch (err) {
							if (DocumentPicker.isCancel(err)) {
								// ignore
							} else {
								console.error(err)
							}
						}
					}}
					avatar={
github bnankiewicz / organic / src / modules / startup / screens / splash.tsx View on Github external
const openPicker = async () => {
  console.tron.debug(DocumentPicker.types)
  try {
    const res = await DocumentPicker.pick({
      type: [DocumentPicker.types.allFiles],
    })
    console.log(
      res.uri,
      res.type, // mime type
      res.name,
      res.size
    )
    console.tron.debug('URI')
    console.tron.debug(res)
    const name = decodeURIComponent(res.uri)

    if (name.startsWith(CONTENT_PREFIXES.RESILLIO_SYNC)) {
      const realPath = name.replace(CONTENT_PREFIXES.RESILLIO_SYNC, '')
      const content = await RNFetchBlob.fs.readFile(realPath, 'utf8')
      const stat = await RNFetchBlob.fs.stat(realPath, 'utf8')
github mattermost / mattermost-mobile / app / components / attachment_button / index.js View on Github external
attachFileFromFiles = async () => {
        const {browseFileTypes} = this.props;
        const hasPermission = await this.hasStoragePermission();

        if (hasPermission) {
            try {
                const res = await DocumentPicker.pick({type: [browseFileTypes]});
                if (Platform.OS === 'android') {
                    // For android we need to retrieve the realPath in case the file being imported is from the cloud
                    const newUri = await ShareExtension.getFilePath(res.uri);
                    if (newUri.filePath) {
                        res.uri = newUri.filePath;
                    } else {
                        return;
                    }
                }

                // Decode file uri to get the actual path
                res.uri = decodeURIComponent(res.uri);

                this.uploadFiles([res]);
            } catch (error) {
                // Do nothing
github iotaledger / trinity-wallet / src / mobile / src / ui / components / SeedVaultImportComponent.js View on Github external
showDocumentPicker() {
        const { t } = this.props;
        DocumentPicker.pick({
            type: isAndroid ? ['application/octet-stream'] : ['public.data', 'public.item', 'dyn.ah62d4rv4ge8003dcta'],
        })
            .then((res) => {
                let path = res.uri;
                if (path.startsWith('file://')) {
                    path = path.slice(7);
                }
                RNFetchBlob.fs
                    .readFile(path, 'ascii')
                    .then((data) => {
                        this.setState({ seedVault: data });
                        this.props.openPasswordValidationModal();
                    })
                    .catch(() =>
                        this.props.generateAlert(
                            'error',
github jolocom / smartwallet-app / src / ui / recovery / container / importBackup.tsx View on Github external
private getBackupFile = async () => {
    const res = await DocumentPicker.pick({
      type: [DocumentPicker.types.plainText],
    })
    const importedData = await readFile(res.uri)

    const encryptedBackup = this.validateImport(importedData)
    if (encryptedBackup) {
      this.props.recoverIdentity(encryptedBackup)
    }
  }
github RocketChat / Rocket.Chat.ReactNative / app / containers / MessageBox / index.js View on Github external
chooseFile = async() => {
		try {
			const res = await DocumentPicker.pick({
				type: [DocumentPicker.types.allFiles]
			});
			this.showUploadModal({
				filename: res.name,
				size: res.size,
				mime: res.type,
				path: res.uri
			});
		} catch (e) {
			if (!DocumentPicker.isCancel(e)) {
				log(e);
			}
		}
	}
github RocketChat / Rocket.Chat.ReactNative / app / views / NewServerView.js View on Github external
chooseCertificate = async() => {
		try {
			const res = await DocumentPicker.pick({
				type: ['com.rsa.pkcs-12']
			});
			const { uri: path, name } = res;
			Alert.prompt(
				I18n.t('Certificate_password'),
				I18n.t('Whats_the_password_for_your_certificate'),
				[
					{
						text: 'OK',
						onPress: password => this.saveCertificate({ path, name, password })
					}
				],
				'secure-text'
			);
		} catch (e) {
			if (!DocumentPicker.isCancel(e)) {