npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@expo-harmony/expo-document-picker

v57.0.3-harmony.1

Published

HarmonyOS port of expo-document-picker

Readme

@expo-harmony/expo-document-picker

GitHub 仓库 | 官方文档

为 HarmonyOS 上的 React Native 应用提供 Expo DocumentPicker 的原生实现,与官方 expo-document-picker 配套使用。

安装

本包适配 Expo SDK 57。

引入本包前,需要确保应用使用的 HarmonyOS SDK 至少为 API 13(HarmonyOS 5.0.1)。

npm install @expo-harmony/expo-document-picker expo-document-picker@~57.0.3

API 对照表

Methods

DocumentPicker.getDocumentAsync(options?)

打开系统文件选择器,返回 Promise<DocumentPickerResult>。用户选中文件时,canceled 为 false,assets 是所选文件数组;用户取消时,canceled 为 true,assets 为 null。

省略 options 时,type 默认为 '*/*'、multiple 默认为 false、copyToCacheDirectory 默认为 true。同一 UIAbility 的上一次选择尚未结束时再次调用,会抛出 ERR_PICKING_IN_PROGRESS。没有可用 UIAbility 时抛出 ERR_DOCUMENT_PICKER_UNAVAILABLE。

import * as DocumentPicker from 'expo-document-picker';

const result = await DocumentPicker.getDocumentAsync({
  type: ['application/pdf', 'image/*'],
  multiple: true,
});

Types

DocumentPickerOptions

| 属性 | 类型 | 默认值 | 说明 | | --- | --- | --- | --- | | type | string \| string[] | '*/*' | 允许选择的 MIME 类型;支持 image/* 等通配符。 | | multiple | boolean | false | 是否允许一次选择多个文件。为 false 时最多选择一个。为 true 时,API 13–20 最多选择 500 个,API 21 起使用系统默认上限。 | | copyToCacheDirectory | boolean | true | 是否将所选文件复制到应用缓存目录。为 true 时 uri 指向副本;为 false 时 uri 是系统返回的原始地址,其可读性和有效期由系统决定。 |

  • base64:HarmonyOS 不返回 Base64 内容,uri 仍为文件地址。

系统按文件后缀过滤候选文件,返回结果后模块也会核对所选文件的后缀。后缀来自 HarmonyOS UTD 注册表,*/* 允许任意后缀。指定多个 MIME 类型时,使用系统能够识别的类型对应的全部后缀。选择器根据用户选择提供临时访问授权,无需在应用中声明文件访问权限。鸿蒙文件选择指南

DocumentPickerAsset

| 属性 | 类型 | 说明 | | --- | --- | --- | | uri | string | 文件地址;默认指向缓存目录中的副本。 | | name | string | 文件名。 | | size | number | 文件大小,单位为字节;无法读取时省略。 | | mimeType | string | 根据文件名后缀确定的 MIME 类型;无法确定时省略。 | | lastModified | number | 最后修改时间,Unix 纪元以来的毫秒数;无法读取时使用当前时间。 |

  • file 和 base64:HarmonyOS 不返回这两个字段。

HarmonyOS SDK API 15 及以上版本可提供更高精度的最后修改时间;较早版本使用秒精度的系统时间。Unix 纪元前的修改时间以负数毫秒表示。

DocumentPickerResult

DocumentPickerSuccessResult | DocumentPickerCanceledResult。

DocumentPickerSuccessResult

| 属性 | 类型 | 说明 | | --- | --- | --- | | canceled | false | 用户没有取消选择。 | | assets | DocumentPickerAsset[] | 所选文件。 |

  • output:HarmonyOS 不返回此字段。

DocumentPickerCanceledResult

| 属性 | 类型 | 说明 | | --- | --- | --- | | canceled | true | 用户取消了选择。 | | assets | null | 取消时没有文件列表。 |

  • output:HarmonyOS 不返回此字段。

Error codes

ERR_DOCUMENT_PICKER_OPTIONS_EMPTY_LIST

type 为空数组时抛出。

ERR_DOCUMENT_PICKER_UNSUPPORTED_MIME_TYPE

除 */* 外,指定的 MIME 类型均无法从 HarmonyOS SDK 的注册表取得对应文件后缀时抛出。

ERR_DOCUMENT_PICKER_MIME_TYPE_MISMATCH

系统返回的文件后缀超出 type 对应的范围时抛出。

ERR_PICKING_IN_PROGRESS

同一 UIAbility 的上一次文件选择尚未结束时再次调用 getDocumentAsync(),会抛出此错误。

ERR_DOCUMENT_PICKER_UNAVAILABLE

没有可用 UIAbility 或设备缺少系统文档选择能力时抛出。

ERR_FAILED_TO_READ_DOCUMENT

所选对象不是普通文件、文件名不合法或文件信息读取失败时抛出。

ERR_DOCUMENT_PICKER_FAILED

系统文件选择器调用失败或选择结果准备失败时抛出。

ERR_DOCUMENT_PICKER_DESTROYED

模块运行环境已销毁时抛出。

Author

expo-harmony © Baoshuo, Released under the MIT License. Authored and maintained by Baoshuo with help from contributors.

Personal Website · Blog · GitHub @renbaoshuo · Twitter @renbaoshuo