expo-document-picker 13.1.0-canary-20250131-5c4e588 → 13.1.0-canary-20250219-4a5dade

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -14,6 +14,7 @@
14
14
 
15
15
  - [Android] Started using expo modules gradle plugin. ([#34176](https://github.com/expo/expo/pull/34176) by [@lukmccall](https://github.com/lukmccall))
16
16
  - [apple] Migrate remaining `expo-module.config.json` to unified platform syntax. ([#34445](https://github.com/expo/expo/pull/34445) by [@reichhartd](https://github.com/reichhartd))
17
+ - [web] Add option to disable file reader to read base64 from file on successfull picking. ([#34739](https://github.com/expo/expo/pull/34739) by [@danilaplee](https://github.com/danilaplee))
17
18
 
18
19
  ## 13.0.1 — 2024-10-22
19
20
 
@@ -1,22 +1,6 @@
1
- apply plugin: 'com.android.library'
2
-
3
- def useLegacyExpoModulesCorePlugin = {
4
- def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
5
- apply from: expoModulesCorePlugin
6
- applyKotlinExpoModulesCorePlugin()
7
- useCoreDependencies()
8
- useDefaultAndroidSdkVersions()
9
- useExpoPublishing()
10
- }
11
-
12
- try {
13
- apply plugin: 'expo-module-gradle-plugin'
14
- } catch (e) {
15
- if (!e instanceof UnknownPluginException) {
16
- throw e
17
- }
18
-
19
- useLegacyExpoModulesCorePlugin()
1
+ plugins {
2
+ id 'com.android.library'
3
+ id 'expo-module-gradle-plugin'
20
4
  }
21
5
 
22
6
  group = 'host.exp.exponent'
@@ -1,6 +1,6 @@
1
1
  import { DocumentPickerOptions, DocumentPickerResult } from './types';
2
2
  declare const _default: {
3
- getDocumentAsync({ type, multiple, }: DocumentPickerOptions): Promise<DocumentPickerResult>;
3
+ getDocumentAsync({ type, multiple, base64, }: DocumentPickerOptions): Promise<DocumentPickerResult>;
4
4
  };
5
5
  export default _default;
6
6
  //# sourceMappingURL=ExpoDocumentPicker.web.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoDocumentPicker.web.d.ts","sourceRoot":"","sources":["../src/ExpoDocumentPicker.web.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;;0CAMtF,qBAAqB,GAAG,QAAQ,oBAAoB,CAAC;;AAJ1D,wBAiDE"}
1
+ {"version":3,"file":"ExpoDocumentPicker.web.d.ts","sourceRoot":"","sources":["../src/ExpoDocumentPicker.web.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;;kDAOtF,qBAAqB,GAAG,QAAQ,oBAAoB,CAAC;;AAL1D,wBAkDE"}
@@ -1,6 +1,6 @@
1
1
  import { Platform } from 'expo-modules-core';
2
2
  export default {
3
- async getDocumentAsync({ type = '*/*', multiple = false, }) {
3
+ async getDocumentAsync({ type = '*/*', multiple = false, base64 = true, }) {
4
4
  // SSR guard
5
5
  if (!Platform.isDOMAvailable) {
6
6
  return { canceled: true, assets: null };
@@ -19,7 +19,7 @@ export default {
19
19
  if (input.files) {
20
20
  const results = [];
21
21
  for (let i = 0; i < input.files.length; i++) {
22
- results.push(readFileAsync(input.files[i]));
22
+ results.push(readFileAsync(input.files[i], base64));
23
23
  }
24
24
  try {
25
25
  const assets = await Promise.all(results);
@@ -42,9 +42,20 @@ export default {
42
42
  });
43
43
  },
44
44
  };
45
- function readFileAsync(targetFile) {
45
+ function readFileAsync(targetFile, base64 = true) {
46
46
  return new Promise((resolve, reject) => {
47
47
  const mimeType = targetFile.type;
48
+ if (!base64) {
49
+ resolve({
50
+ uri: targetFile.webkitRelativePath,
51
+ mimeType,
52
+ name: targetFile.name,
53
+ lastModified: targetFile.lastModified,
54
+ size: targetFile.size,
55
+ file: targetFile,
56
+ });
57
+ return;
58
+ }
48
59
  const reader = new FileReader();
49
60
  reader.onerror = () => {
50
61
  reject(new Error(`Failed to read the selected media because the operation failed.`));
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoDocumentPicker.web.js","sourceRoot":"","sources":["../src/ExpoDocumentPicker.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAI7C,eAAe;IACb,KAAK,CAAC,gBAAgB,CAAC,EACrB,IAAI,GAAG,KAAK,EACZ,QAAQ,GAAG,KAAK,GACM;QACtB,YAAY;QACZ,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE;YAC5B,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;SACzC;QAED,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC9C,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;QAC7B,KAAK,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACnC,KAAK,CAAC,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC1E,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAChD,IAAI,QAAQ,EAAE;YACZ,KAAK,CAAC,YAAY,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;SAC5C;QAED,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAEjC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,KAAK,CAAC,gBAAgB,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;gBAC1C,IAAI,KAAK,CAAC,KAAK,EAAE;oBACf,MAAM,OAAO,GAAmC,EAAE,CAAC;oBACnD,KAAK,I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pB,MAAM,CAAC,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC,CAAC;QACvF,CAAC,CAAC;QACF,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;YAC7B,MAAM,GAAG,GAAI,MAAc,CAAC,MAAM,CAAC;YACnC,OAAO,CAAC;gBACN,GAAG;gBACH,QAAQ;gBACR,IAAI,EAAE,UAAU,CAAC,IAAI;gBACrB,YAAY,EAAE,UAAU,CAAC,YAAY;gBACrC,IAAI,EAAE,UAAU,CAAC,IAAI;gBACrB,IAAI,EAAE,UAAU;aACjB,CAAC,CAAC;QACL,CAAC,CAAC;QAEF,6CAA6C;QAC7C,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { Platform } from 'expo-modules-core';\n\nimport { DocumentPickerAsset, DocumentPickerOptions, DocumentPickerResult } from './types';\n\nexport default {\n async getDocumentAsync({\n type = '*/*',\n multiple = false,\n }: DocumentPickerOptions): Promise<DocumentPickerResult> {\n // SSR guard\n if (!Platform.isDOMAvailable) {\n return { canceled: true, assets: null };\n }\n\n const input = document.createElement('input');\n input.style.display = 'none';\n input.setAttribute('type', 'file');\n input.setAttribute('accept', Array.isArray(type) ? type.join(',') : type);\n input.setAttribute('id', String(Math.random()));\n if (multiple) {\n input.setAttribute('multiple', 'multiple');\n }\n\n document.body.appendChild(input);\n\n return new Promise((resolve, reject) => {\n input.addEventListener('change', async () => {\n if (input.files) {\n const results: Promise<DocumentPickerAsset>[] = [];\n for (let i = 0; i < input.files.length; i++) {\n results.push(readFileAsync(input.files[i]));\n }\n try {\n const assets = await Promise.all(results);\n resolve({ canceled: false, assets, output: input.files });\n } catch (e) {\n reject(e);\n }\n } else {\n resolve({ canceled: true, assets: null });\n }\n\n document.body.removeChild(input);\n });\n\n input.addEventListener('cancel', () => {\n resolve({ canceled: true, assets: null });\n });\n\n const event = new MouseEvent('click');\n input.dispatchEvent(event);\n });\n },\n};\n\nfunction readFileAsync(targetFile: File): Promise<DocumentPickerAsset> {\n return new Promise((resolve, reject) => {\n const mimeType = targetFile.type;\n\n const reader = new FileReader();\n reader.onerror = () => {\n reject(new Error(`Failed to read the selected media because the operation failed.`));\n };\n reader.onload = ({ target }) => {\n const uri = (target as any).result;\n resolve({\n uri,\n mimeType,\n name: targetFile.name,\n lastModified: targetFile.lastModified,\n size: targetFile.size,\n file: targetFile,\n });\n };\n\n // Read in the image file as a binary string.\n reader.readAsDataURL(targetFile);\n });\n}\n"]}
1
+ {"version":3,"file":"ExpoDocumentPicker.web.js","sourceRoot":"","sources":["../src/ExpoDocumentPicker.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAI7C,eAAe;IACb,KAAK,CAAC,gBAAgB,CAAC,EACrB,IAAI,GAAG,KAAK,EACZ,QAAQ,GAAG,KAAK,EAChB,MAAM,GAAG,IAAI,GACS;QACtB,YAAY;QACZ,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE;YAC5B,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;SACzC;QAED,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC9C,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;QAC7B,KAAK,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACnC,KAAK,CAAC,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC1E,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAChD,IAAI,QAAQ,EAAE;YACZ,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OAAO,CAAC,CAAC;YACtC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC;AAEF,SAAS,aAAa,CAAC,UAAgB,EAAE,SAAkB,IAAI;IAC7D,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC;QACjC,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,CAAC;gBACN,GAAG,EAAE,UAAU,CAAC,kBAAkB;gBAClC,QAAQ;gBACR,IAAI,EAAE,UAAU,CAAC,IAAI;gBACrB,YAAY,EAAE,UAAU,CAAC,YAAY;gBACrC,IAAI,EAAE,UAAU,CAAC,IAAI;gBACrB,IAAI,EAAE,UAAU;aACjB,CAAC,CAAC;YACH,OAAO;SACR;QACD,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAChC,MAAM,CAAC,OAAO,GAAG,GAAG,EAAE;YACpB,MAAM,CAAC,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC,CAAC;QACvF,CAAC,CAAC;QACF,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;YAC7B,MAAM,GAAG,GAAI,MAAc,CAAC,MAAM,CAAC;YACnC,OAAO,CAAC;gBACN,GAAG;gBACH,QAAQ;gBACR,IAAI,EAAE,UAAU,CAAC,IAAI;gBACrB,YAAY,EAAE,UAAU,CAAC,YAAY;gBACrC,IAAI,EAAE,UAAU,CAAC,IAAI;gBACrB,IAAI,EAAE,UAAU;aACjB,CAAC,CAAC;QACL,CAAC,CAAC;QAEF,6CAA6C;QAC7C,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { Platform } from 'expo-modules-core';\n\nimport { DocumentPickerAsset, DocumentPickerOptions, DocumentPickerResult } from './types';\n\nexport default {\n async getDocumentAsync({\n type = '*/*',\n multiple = false,\n base64 = true,\n }: DocumentPickerOptions): Promise<DocumentPickerResult> {\n // SSR guard\n if (!Platform.isDOMAvailable) {\n return { canceled: true, assets: null };\n }\n\n const input = document.createElement('input');\n input.style.display = 'none';\n input.setAttribute('type', 'file');\n input.setAttribute('accept', Array.isArray(type) ? type.join(',') : type);\n input.setAttribute('id', String(Math.random()));\n if (multiple) {\n input.setAttribute('multiple', 'multiple');\n }\n\n document.body.appendChild(input);\n\n return new Promise((resolve, reject) => {\n input.addEventListener('change', async () => {\n if (input.files) {\n const results: Promise<DocumentPickerAsset>[] = [];\n for (let i = 0; i < input.files.length; i++) {\n results.push(readFileAsync(input.files[i], base64));\n }\n try {\n const assets = await Promise.all(results);\n resolve({ canceled: false, assets, output: input.files });\n } catch (e) {\n reject(e);\n }\n } else {\n resolve({ canceled: true, assets: null });\n }\n\n document.body.removeChild(input);\n });\n\n input.addEventListener('cancel', () => {\n resolve({ canceled: true, assets: null });\n });\n\n const event = new MouseEvent('click');\n input.dispatchEvent(event);\n });\n },\n};\n\nfunction readFileAsync(targetFile: File, base64: boolean = true): Promise<DocumentPickerAsset> {\n return new Promise((resolve, reject) => {\n const mimeType = targetFile.type;\n if (!base64) {\n resolve({\n uri: targetFile.webkitRelativePath,\n mimeType,\n name: targetFile.name,\n lastModified: targetFile.lastModified,\n size: targetFile.size,\n file: targetFile,\n });\n return;\n }\n const reader = new FileReader();\n reader.onerror = () => {\n reject(new Error(`Failed to read the selected media because the operation failed.`));\n };\n reader.onload = ({ target }) => {\n const uri = (target as any).result;\n resolve({\n uri,\n mimeType,\n name: targetFile.name,\n lastModified: targetFile.lastModified,\n size: targetFile.size,\n file: targetFile,\n });\n };\n\n // Read in the image file as a binary string.\n reader.readAsDataURL(targetFile);\n });\n}\n"]}
package/build/index.d.ts CHANGED
@@ -10,6 +10,6 @@ import { DocumentPickerOptions, DocumentPickerResult } from './types';
10
10
  *
11
11
  * If the user cancelled the document picking, the promise resolves to `{ type: 'cancel' }`.
12
12
  */
13
- export declare function getDocumentAsync({ type, copyToCacheDirectory, multiple, }?: DocumentPickerOptions): Promise<DocumentPickerResult>;
13
+ export declare function getDocumentAsync({ type, copyToCacheDirectory, multiple, base64, }?: DocumentPickerOptions): Promise<DocumentPickerResult>;
14
14
  export * from './types';
15
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAGtE;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,IAAY,EACZ,oBAA2B,EAC3B,QAAgB,GACjB,GAAE,qBAA0B,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAS5D;AAED,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAGtE;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,IAAY,EACZ,oBAA2B,EAC3B,QAAgB,EAChB,MAAa,GACd,GAAE,qBAA0B,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAU5D;AAED,cAAc,SAAS,CAAC"}
package/build/index.js CHANGED
@@ -11,7 +11,7 @@ import ExpoDocumentPicker from './ExpoDocumentPicker';
11
11
  *
12
12
  * If the user cancelled the document picking, the promise resolves to `{ type: 'cancel' }`.
13
13
  */
14
- export async function getDocumentAsync({ type = '*/*', copyToCacheDirectory = true, multiple = false, } = {}) {
14
+ export async function getDocumentAsync({ type = '*/*', copyToCacheDirectory = true, multiple = false, base64 = true, } = {}) {
15
15
  if (typeof type === 'string') {
16
16
  type = [type];
17
17
  }
@@ -19,6 +19,7 @@ export async function getDocumentAsync({ type = '*/*', copyToCacheDirectory = tr
19
19
  type,
20
20
  copyToCacheDirectory,
21
21
  multiple,
22
+ base64,
22
23
  });
23
24
  }
24
25
  export * from './types';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAGtD,cAAc;AACd;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,EACrC,IAAI,GAAG,KAAK,EACZ,oBAAoB,GAAG,IAAI,EAC3B,QAAQ,GAAG,KAAK,MACS,EAAE;IAC3B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,IAAI,GAAG,CAAC,IAAI,CAAa,CAAC;KAC3B;IACD,OAAO,MAAM,kBAAkB,CAAC,gBAAgB,CAAC;QAC/C,IAAI;QACJ,oBAAoB;QACpB,QAAQ;KACT,CAAC,CAAC;AACL,CAAC;AAED,cAAc,SAAS,CAAC","sourcesContent":["import ExpoDocumentPicker from './ExpoDocumentPicker';\nimport { DocumentPickerOptions, DocumentPickerResult } from './types';\n\n// @needsAudit\n/**\n * Display the system UI for choosing a document. By default, the chosen file is copied to [the app's internal cache directory](filesystem/#filesystemcachedirectory).\n * > **Notes for Web:** The system UI can only be shown after user activation (e.g. a `Button` press).\n * > Therefore, calling `getDocumentAsync` in `componentDidMount`, for example, will **not** work as\n * > intended. The `cancel` event will not be returned in the browser due to platform restrictions and\n * > inconsistencies across browsers.\n *\n * @return On success returns a promise that fulfils with [`DocumentPickerResult`](#documentpickerresult) object.\n *\n * If the user cancelled the document picking, the promise resolves to `{ type: 'cancel' }`.\n */\nexport async function getDocumentAsync({\n type = '*/*',\n copyToCacheDirectory = true,\n multiple = false,\n}: DocumentPickerOptions = {}): Promise<DocumentPickerResult> {\n if (typeof type === 'string') {\n type = [type] as string[];\n }\n return await ExpoDocumentPicker.getDocumentAsync({\n type,\n copyToCacheDirectory,\n multiple,\n });\n}\n\nexport * from './types';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAGtD,cAAc;AACd;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,EACrC,IAAI,GAAG,KAAK,EACZ,oBAAoB,GAAG,IAAI,EAC3B,QAAQ,GAAG,KAAK,EAChB,MAAM,GAAG,IAAI,MACY,EAAE;IAC3B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,IAAI,GAAG,CAAC,IAAI,CAAa,CAAC;KAC3B;IACD,OAAO,MAAM,kBAAkB,CAAC,gBAAgB,CAAC;QAC/C,IAAI;QACJ,oBAAoB;QACpB,QAAQ;QACR,MAAM;KACP,CAAC,CAAC;AACL,CAAC;AAED,cAAc,SAAS,CAAC","sourcesContent":["import ExpoDocumentPicker from './ExpoDocumentPicker';\nimport { DocumentPickerOptions, DocumentPickerResult } from './types';\n\n// @needsAudit\n/**\n * Display the system UI for choosing a document. By default, the chosen file is copied to [the app's internal cache directory](filesystem/#filesystemcachedirectory).\n * > **Notes for Web:** The system UI can only be shown after user activation (e.g. a `Button` press).\n * > Therefore, calling `getDocumentAsync` in `componentDidMount`, for example, will **not** work as\n * > intended. The `cancel` event will not be returned in the browser due to platform restrictions and\n * > inconsistencies across browsers.\n *\n * @return On success returns a promise that fulfils with [`DocumentPickerResult`](#documentpickerresult) object.\n *\n * If the user cancelled the document picking, the promise resolves to `{ type: 'cancel' }`.\n */\nexport async function getDocumentAsync({\n type = '*/*',\n copyToCacheDirectory = true,\n multiple = false,\n base64 = true,\n}: DocumentPickerOptions = {}): Promise<DocumentPickerResult> {\n if (typeof type === 'string') {\n type = [type] as string[];\n }\n return await ExpoDocumentPicker.getDocumentAsync({\n type,\n copyToCacheDirectory,\n multiple,\n base64,\n });\n}\n\nexport * from './types';\n"]}
package/build/types.d.ts CHANGED
@@ -20,6 +20,13 @@ export type DocumentPickerOptions = {
20
20
  *
21
21
  */
22
22
  multiple?: boolean;
23
+ /**
24
+ * If `true`, asset url is base64 from the file
25
+ * If `false`, asset url is the file url parameter
26
+ * @platform web
27
+ * @default true
28
+ */
29
+ base64?: boolean;
23
30
  };
24
31
  export type DocumentPickerAsset = {
25
32
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,IAAI,CAAC,EAAE,IAAI,CAAC;CACb,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,2BAA2B,GAAG,4BAA4B,CAAC;AAE9F;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC;IAChB;;OAEG;IACH,MAAM,EAAE,mBAAmB,EAAE,CAAC;IAC9B;;;OAGG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC;;OAEG;IACH,QAAQ,EAAE,IAAI,CAAC;IACf;;OAEG;IACH,MAAM,EAAE,IAAI,CAAC;IACb;;;OAGG;IACH,MAAM,CAAC,EAAE,IAAI,CAAC;CACf,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,IAAI,CAAC,EAAE,IAAI,CAAC;CACb,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,2BAA2B,GAAG,4BAA4B,CAAC;AAE9F;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC;IAChB;;OAEG;IACH,MAAM,EAAE,mBAAmB,EAAE,CAAC;IAC9B;;;OAGG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC;;OAEG;IACH,QAAQ,EAAE,IAAI,CAAC;IACf;;OAEG;IACH,MAAM,EAAE,IAAI,CAAC;IACb;;;OAGG;IACH,MAAM,CAAC,EAAE,IAAI,CAAC;CACf,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["// @needsAudit\nexport type DocumentPickerOptions = {\n /**\n * The [MIME type(s)](https://en.wikipedia.org/wiki/Media_type) of the documents that are available\n * to be picked. It also supports wildcards like `'image/*'` to choose any image. To allow any type\n * of document you can use `'&ast;/*'`.\n * @default '&ast;/*'\n */\n type?: string | string[];\n /**\n * If `true`, the picked file is copied to [`FileSystem.CacheDirectory`](./filesystem#filesystemcachedirectory),\n * which allows other Expo APIs to read the file immediately. This may impact performance for\n * large files, so you should consider setting this to `false` if you expect users to pick\n * particularly large files and your app does not need immediate read access.\n * @default true\n */\n copyToCacheDirectory?: boolean;\n /**\n * Allows multiple files to be selected from the system UI.\n * @default false\n *\n */\n multiple?: boolean;\n};\n\nexport type DocumentPickerAsset = {\n /**\n * Document original name.\n */\n name: string;\n /**\n * Document size in bytes.\n */\n size?: number;\n /**\n * An URI to the local document file.\n */\n uri: string;\n /**\n * Document MIME type.\n */\n mimeType?: string;\n /**\n * Timestamp of last document modification.\n */\n lastModified?: number;\n /**\n * `File` object for the parity with web File API.\n * @platform web\n */\n file?: File;\n};\n\n/**\n * Type representing successful and canceled document pick result.\n */\nexport type DocumentPickerResult = DocumentPickerSuccessResult | DocumentPickerCanceledResult;\n\n/**\n * Type representing successful pick result.\n */\nexport type DocumentPickerSuccessResult = {\n /**\n * If asset data have been returned this should always be `false`.\n */\n canceled: false;\n /**\n * An array of picked assets.\n */\n assets: DocumentPickerAsset[];\n /**\n * `FileList` object for the parity with web File API.\n * @platform web\n */\n output?: FileList;\n};\n\n/**\n * Type representing canceled pick result.\n */\nexport type DocumentPickerCanceledResult = {\n /**\n * Always `true` when the request was canceled.\n */\n canceled: true;\n /**\n * Always `null` when the request was canceled.\n */\n assets: null;\n /**\n * Always `null` when the request was canceled.\n * @platform web\n */\n output?: null;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["// @needsAudit\nexport type DocumentPickerOptions = {\n /**\n * The [MIME type(s)](https://en.wikipedia.org/wiki/Media_type) of the documents that are available\n * to be picked. It also supports wildcards like `'image/*'` to choose any image. To allow any type\n * of document you can use `'&ast;/*'`.\n * @default '&ast;/*'\n */\n type?: string | string[];\n /**\n * If `true`, the picked file is copied to [`FileSystem.CacheDirectory`](./filesystem#filesystemcachedirectory),\n * which allows other Expo APIs to read the file immediately. This may impact performance for\n * large files, so you should consider setting this to `false` if you expect users to pick\n * particularly large files and your app does not need immediate read access.\n * @default true\n */\n copyToCacheDirectory?: boolean;\n /**\n * Allows multiple files to be selected from the system UI.\n * @default false\n *\n */\n multiple?: boolean;\n /**\n * If `true`, asset url is base64 from the file\n * If `false`, asset url is the file url parameter\n * @platform web\n * @default true\n */\n base64?: boolean;\n};\n\nexport type DocumentPickerAsset = {\n /**\n * Document original name.\n */\n name: string;\n /**\n * Document size in bytes.\n */\n size?: number;\n /**\n * An URI to the local document file.\n */\n uri: string;\n /**\n * Document MIME type.\n */\n mimeType?: string;\n /**\n * Timestamp of last document modification.\n */\n lastModified?: number;\n /**\n * `File` object for the parity with web File API.\n * @platform web\n */\n file?: File;\n};\n\n/**\n * Type representing successful and canceled document pick result.\n */\nexport type DocumentPickerResult = DocumentPickerSuccessResult | DocumentPickerCanceledResult;\n\n/**\n * Type representing successful pick result.\n */\nexport type DocumentPickerSuccessResult = {\n /**\n * If asset data have been returned this should always be `false`.\n */\n canceled: false;\n /**\n * An array of picked assets.\n */\n assets: DocumentPickerAsset[];\n /**\n * `FileList` object for the parity with web File API.\n * @platform web\n */\n output?: FileList;\n};\n\n/**\n * Type representing canceled pick result.\n */\nexport type DocumentPickerCanceledResult = {\n /**\n * Always `true` when the request was canceled.\n */\n canceled: true;\n /**\n * Always `null` when the request was canceled.\n */\n assets: null;\n /**\n * Always `null` when the request was canceled.\n * @platform web\n */\n output?: null;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-document-picker",
3
- "version": "13.1.0-canary-20250131-5c4e588",
3
+ "version": "13.1.0-canary-20250219-4a5dade",
4
4
  "description": "Provides access to the system's UI for selecting documents from the available providers on the user's device.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -35,9 +35,10 @@
35
35
  "preset": "expo-module-scripts"
36
36
  },
37
37
  "devDependencies": {
38
- "expo-module-scripts": "4.0.4-canary-20250131-5c4e588"
38
+ "expo-module-scripts": "4.0.5-canary-20250219-4a5dade"
39
39
  },
40
40
  "peerDependencies": {
41
- "expo": "53.0.0-canary-20250131-5c4e588"
42
- }
41
+ "expo": "53.0.0-canary-20250219-4a5dade"
42
+ },
43
+ "gitHead": "4a5daded61d3d8b9d501059039ac74c09c25675b"
43
44
  }
@@ -6,6 +6,7 @@ export default {
6
6
  async getDocumentAsync({
7
7
  type = '*/*',
8
8
  multiple = false,
9
+ base64 = true,
9
10
  }: DocumentPickerOptions): Promise<DocumentPickerResult> {
10
11
  // SSR guard
11
12
  if (!Platform.isDOMAvailable) {
@@ -28,7 +29,7 @@ export default {
28
29
  if (input.files) {
29
30
  const results: Promise<DocumentPickerAsset>[] = [];
30
31
  for (let i = 0; i < input.files.length; i++) {
31
- results.push(readFileAsync(input.files[i]));
32
+ results.push(readFileAsync(input.files[i], base64));
32
33
  }
33
34
  try {
34
35
  const assets = await Promise.all(results);
@@ -53,10 +54,20 @@ export default {
53
54
  },
54
55
  };
55
56
 
56
- function readFileAsync(targetFile: File): Promise<DocumentPickerAsset> {
57
+ function readFileAsync(targetFile: File, base64: boolean = true): Promise<DocumentPickerAsset> {
57
58
  return new Promise((resolve, reject) => {
58
59
  const mimeType = targetFile.type;
59
-
60
+ if (!base64) {
61
+ resolve({
62
+ uri: targetFile.webkitRelativePath,
63
+ mimeType,
64
+ name: targetFile.name,
65
+ lastModified: targetFile.lastModified,
66
+ size: targetFile.size,
67
+ file: targetFile,
68
+ });
69
+ return;
70
+ }
60
71
  const reader = new FileReader();
61
72
  reader.onerror = () => {
62
73
  reject(new Error(`Failed to read the selected media because the operation failed.`));
package/src/index.ts CHANGED
@@ -17,6 +17,7 @@ export async function getDocumentAsync({
17
17
  type = '*/*',
18
18
  copyToCacheDirectory = true,
19
19
  multiple = false,
20
+ base64 = true,
20
21
  }: DocumentPickerOptions = {}): Promise<DocumentPickerResult> {
21
22
  if (typeof type === 'string') {
22
23
  type = [type] as string[];
@@ -25,6 +26,7 @@ export async function getDocumentAsync({
25
26
  type,
26
27
  copyToCacheDirectory,
27
28
  multiple,
29
+ base64,
28
30
  });
29
31
  }
30
32
 
package/src/types.ts CHANGED
@@ -21,6 +21,13 @@ export type DocumentPickerOptions = {
21
21
  *
22
22
  */
23
23
  multiple?: boolean;
24
+ /**
25
+ * If `true`, asset url is base64 from the file
26
+ * If `false`, asset url is the file url parameter
27
+ * @platform web
28
+ * @default true
29
+ */
30
+ base64?: boolean;
24
31
  };
25
32
 
26
33
  export type DocumentPickerAsset = {