🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

expo-open-with-file

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expo-open-with-file

Allow users to open your app when selecting files in other apps

0.1.4
latest
Source
npm
Version published
Maintainers
1
Created
Source

expo-open-with-file

Allow users to open your expo iOS / Android app when selecting files in other apps.

Install

npx expo install expo-open-with-file

Basic setup

Add plugin in app.json, and run expo prebuild

{
  "plugins": [
    [
      "expo-open-with-file",
      {
        "types": [
          {
            "extension": "dlc"
          }
        ]
      }
    ]
  ]
}

Usage

To access the file, use useOpenWithFile. This will give you some file info (if available, like size, uri...) and the contents of the file in Base64.

export  default  function  App() {
    const { file } =  useOpenWithFile({ resetOnBackground:  true });

    useEffect(() => {
        if (file) {
	    console.log('Info', JSON.stringify(file.info));
	    console.log('Base64', JSON.stringify(file.base64));
	}
    }, [file]);

    return (
	<View  style={{ flex:  1, alignItems:  'center', justifyContent:  'center' }}>
	    <Text>File: {file?.info.uri || 'none'}</Text>
	</View>
    );
}

Optional configurations

You can provide extra properties for iOS to support opening documents in place. This will use the native module for requesting access to read the file.

{
  "plugins": [
    [
      "expo-open-with-file",
      {
        "types": [
          {
            "extension": "dlc"
          }
        ],
        "custom": {
          "ios": {
	     "supportsDocumentBrowser": true,
	     "supportsFileSharingEnabled": true,
  	     "supportsOpeningDocumentsInPlace": true,
          }
        }
      }
    ]
  ]
}
PropDefaultDocs
supportsDocumentBrowserfalse# UISupportsDocumentBrowser
supportsFileSharingEnabledfalse# UIFileSharingEnabled
supportsOpeningDocumentsInPlacefalse# LSSupportsOpeningDocumentsInPlace

File type configurations

The plugin uses a default configuration to make set up easy. Lots of properties are configurable so you can customise for your use case.

{
  "plugins": [
    [
      "expo-open-with-file",
      {
        "types": [
          {
            "extension": "dlc",
            "custom": {
              "ios": {
                "typeConformsTo": [
                  "public.data",
                  "public.item"
                ],
                "typeDescription": "DLC",
                "typeIdentifier": "com.example.dlc",
                "bundleTypeRole": "Editor",
                "handlerRank": "Owner"
              },
              "android": {
                "actions": [
                  "VIEW",
                  "EDIT"
                ],
                "categories": [
                  "BROWSABLE",
                  "DEFAULT"
                ],
                "mimeTypes": [
                  "application/dlc",
                  "application/octet-stream"
                ],
                "schemes": [
                  "file",
                  "content"
                ],
                "hosts": [],
                "pathPatterns": [
                  ".*\\\\.dlc",
                  ".*\\\\..*\\\\.dlc",
                  ".*\\\\..*\\\\..*\\\\.dlc"
                ]
              }
            }
          }
        ]
      }
    ]
  ]
}

iOS custom props

PropDefaultMaps to
typeConformsTopublic.data & public.itemUTTypeConformsTo
typeDescriptionextension.toUpperCase()UTTypeDescription
typeIdentifiercom.${config.name}.${extension}.toLowerCase()UTTypeIdentifier
bundleTypeRoleEditorCFBundleTypeRole
handlerRankOwnerLSHandlerRank

Android custom props

PropDefaultMaps to
actionsVIEW & EDITandroid.intent.action.${action}
categoriesBROWSABLE & DEFAULTandroid.intent.category.${category}
mimeTypesapplication/${extension} & application/octet-streamandroid:mimeType
schemesfile & contentandroid:scheme
hostsEmpty (none)android:host
pathPatterns.*\\\\.${extension} & .*\\\\..*\\\\.${extension} & .*\\\\..*\\\\..*\\\\.${extension}android:pathPattern

Contributions

Please open a PR if you want to provide improvements / extra functionality! This is technically possible without the use of a custom plugin, but this is all about convenience and providing an out of the box solution. If you know how to make this better, please do.

Keywords

react-native

FAQs

Package last updated on 18 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts