Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
* upstream/master: (22 commits)
  5.0.2
  fix: copyTo on android to put the file in a uniquely named dir (react-native-documents#397)
  5.0.1
  Fix copyFile on Android. (react-native-documents#392)
  chore: document RN blob support
  5.0.0
  support only android >=5 (API 21) (react-native-documents#386)
  [Android][Google Drive] Download file from google drive then cache in local storage (react-native-documents#264)
  4.3.0
  [Windows] Implementing Folder Picker support (react-native-documents#380)
  Fix crash on iOS (react-native-documents#383)
  chore: deleted duplicate test case (react-native-documents#375)
  chore: change readme wording
  4.2.0
  iOS : add mode option (react-native-documents#345)
  chore: update comment for closing issues (react-native-documents#373)
  chore: update discussions in readme (react-native-documents#372)
  chore: introduce GH discussions (react-native-documents#371)
  chore: add issue actions (react-native-documents#369)
  chore: update provided file type shortcuts
  ...
  • Loading branch information
DomiR committed Mar 30, 2021
2 parents e9437b4 + 40221a2 commit 2dd6efe
Show file tree
Hide file tree
Showing 11 changed files with 431 additions and 154 deletions.
30 changes: 30 additions & 0 deletions .github/label-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Configuration for Label Actions - https://github.com/dessant/label-actions

# Specify actions for issues and pull requests
actions:
# Actions taken when the `repro-required` label is added
repro-required:
# Post a comment
comment: >
:wave: @{issue-author}, sorry you're having an issue. This issue is being closed because it does not provide all information required by the [issue template](https://raw.githubusercontent.com/react-native-datetimepicker/.github/master/.github/ISSUE_TEMPLATE/bug_report.md).
As the issue template explains, we require that you provide a runnable example that reproduces your issue and your environment information.
This means you need to provide a git repository with code that reproduces the issue.
The reason is that maintainers do not have time to try reproduce bugs themselves. Please try to minimize the superfluous code and focus only on reproducing the bug.
Please create a new issue with this and we'll be happy to review it!
# Lock the thread
lock: true
close: true
# Actions taken when the `repro-required` label is removed
-repro-required:
# Unlock the thread
unlock: true
open: true

# Limit to only `issues` or `pulls`
# only: issues

# Repository to extend settings from
# _extends: repo
57 changes: 40 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
# react-native-document-picker

⚠️ NOTE: since version 3.3.2 we're using git version tags prefixed with `v`, eg. `v3.3.2`. This is a standard format and should mean no changes to your workflows.
🚧🚧 GH discussions available 🚧🚧

If you want to ask questions, we opened [GH discussions](https://github.com/rnmods/react-native-document-picker/discussions) for that purpose! 🤗 Issue tracker is now reserved for bugs and feature requests only and issues not following the issue template can be closed. Thank you!

A React Native wrapper for:

- Apple's `UIDocumentPickerViewController`
- Android's `Intent.ACTION_GET_CONTENT`
- Windows `Windows.Storage.Pickers`

Requires Android 5.0+ and iOS 10+

### Installation

```bash
npm i --save react-native-document-picker

OR

yarn add react-native-document-picker
```

You need to enable iCloud Documents to access iCloud
Expand Down Expand Up @@ -43,12 +50,15 @@ The type or types of documents to allow selection of. May be an array of types a

- On Android these are MIME types such as `text/plain` or partial MIME types such as `image/*`. See [common MIME types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types).
- On iOS these must be Apple "[Uniform Type Identifiers](https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html)"
- If `type` is omitted it will be treated as `*/*` or `public.content`.
- Multiple type strings are not supported on Android before KitKat (API level 19), Jellybean will fall back to `*/*` if you provide an array with more than one value.
- If `type` is omitted it will be treated as `*/*` or `public.item`.

##### [iOS only] `mode`:`"import" | "open"`:

Defaults to `import`. If `mode` is set to `import` the document picker imports the file from outside to inside the sandbox, otherwise if `mode` is set to `open` the document picker opens the file right in place.

##### [iOS only] `copyTo`:`"cachesDirectory" | "documentDirectory"`:
##### [iOS and Android only] `copyTo`:`"cachesDirectory" | "documentDirectory"`:

If specified, the picked file is copied to `NSCachesDirectory` / `NSDocumentDirectory` directory. The uri of the copy will be available in result's `fileCopyUri`. If copying the file fails (eg. due to lack of space), `fileCopyUri` will be the same as `uri`, and more details about the error will be available in `copyError` field in the result.
If specified, the picked file is copied to `NSCachesDirectory` / `NSDocumentDirectory` (iOS) or `getCacheDir` / `getFilesDir` (Android). The uri of the copy will be available in result's `fileCopyUri`. If copying the file fails (eg. due to lack of space), `fileCopyUri` will be the same as `uri`, and more details about the error will be available in `copyError` field in the result.

This should help if you need to work with the file(s) later on, because by default, [the picked documents are temporary files. They remain available only until your application terminates](https://developer.apple.com/documentation/uikit/uidocumentpickerdelegate/2902364-documentpicker). This may impact performance for large files, so keep this in mind if you expect users to pick particularly large files and your app does not need immediate read access.

Expand All @@ -75,11 +85,11 @@ The object a `pick` Promise resolves to or the objects in the array a `pickMulti

##### `uri`:

The URI representing the document picked by the user. _On iOS this will be a `file://` URI for a temporary file in your app's container. On Android this will be a `content://` URI for a document provided by a DocumentProvider that must be accessed with a ContentResolver._
The URI representing the document picked by the user. _On iOS this will be a `file://` URI for a temporary file in your app's container if `mode` is not specified or set at `import` otherwise it will be the original `file://` URI. On Android this will be a `content://` URI for a document provided by a DocumentProvider that must be accessed with a ContentResolver._

##### `fileCopyUri`:

Same as `uri`, but has special meaning on iOS, if `copyTo` option is specified.
Same as `uri`, but has special meaning if `copyTo` option is specified.

##### `type`:

Expand All @@ -101,18 +111,29 @@ The base64 encoded content of the picked file if the option `readContent` was se

`DocumentPicker.types.*` provides a few common types for use as `type` values, these types will use the correct format for each platform (MIME types on Android, UTIs on iOS).

- `DocumentPicker.types.allFiles`: All document types, on Android this is `*/*`, on iOS is `public.content` (note that some binary and archive types do not inherit from `public.content`)
- `DocumentPicker.types.images`: All image types (`image/*` or `public.image`)
- `DocumentPicker.types.plainText`: Plain text files ie: `.txt` (`text/plain` or `public.plain-text`)
- `DocumentPicker.types.audio`: All audio types (`audio/*` or `public.audio`)
- `DocumentPicker.types.pdf`: PDF documents (`application/pdf` or `com.adobe.pdf`)
- `DocumentPicker.types.zip`: Zip files (`application/zip` or `public.zip-archive`)
- `DocumentPicker.types.csv`: Csv files (`text/csv` or `public.comma-separated-values-text`)

### `DocumentPicker.isCancel(err)`
- `DocumentPicker.types.allFiles`: All document types, on Android this is `*/*`, on iOS is `public.item`
- `DocumentPicker.types.images`: All image types
- `DocumentPicker.types.plainText`: Plain text files
- `DocumentPicker.types.audio`: All audio types
- `DocumentPicker.types.pdf`: PDF documents
- `DocumentPicker.types.zip`: Zip files
- `DocumentPicker.types.csv`: Csv files
- `DocumentPicker.types.doc`: doc files
- `DocumentPicker.types.docx`: docx files
- `DocumentPicker.types.ppt`: ppt files
- `DocumentPicker.types.pptx`: pptx files
- `DocumentPicker.types.xls`: xls files
- `DocumentPicker.types.xlsx`: xlsx files

#### `DocumentPicker.isCancel(err)`

If the user cancels the document picker without choosing a file (by pressing the system back button on Android or the Cancel button on iOS) the Promise will be rejected with a cancellation error. You can check for this error using `DocumentPicker.isCancel(err)` allowing you to ignore it and cleanup any parts of your interface that may not be needed anymore.

#### [iOS only] `DocumentPicker.releaseSecureAccess(uris: Array<string>)`

If `mode` is set to `open` iOS is giving you a secure access to a file located outside from your sandbox.
In that case Apple is asking you to release the access as soon as you finish using the resource.

## Example

```javascript
Expand Down Expand Up @@ -165,7 +186,9 @@ try {

## How to send it back ?

I recommend using [https://github.com/johanneslumpe/react-native-fs](https://github.com/johanneslumpe/react-native-fs)
Use blob support that is built-in into react natve - [see comment](https://github.com/rnmods/react-native-document-picker/issues/70#issuecomment-384335402).

Alternatively, use [https://github.com/johanneslumpe/react-native-fs](https://github.com/johanneslumpe/react-native-fs)
I had to modify [Uploader.m](https://gist.github.com/Elyx0/5dc53bef294b42c847f1baea7cc5e911) so it would use `NSFileCoordinator` with `NSFileCoordinatorReadingForUploading` option.

I added a check for file length that would be thrown into RNFS catch block.
Expand Down
4 changes: 0 additions & 4 deletions __tests__/typescript/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ DocumentPicker.pickMultiple({
type: [DocumentPicker.types.allFiles],
});

DocumentPicker.pickMultiple({
type: [DocumentPicker.types.allFiles],
});

DocumentPicker.pickMultiple({
type: [DocumentPicker.types.audio],
});
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
buildToolsVersion safeExtGet("buildToolsVersion", '28.0.3')

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 16)
minSdkVersion safeExtGet('minSdkVersion', 21)
targetSdkVersion safeExtGet('targetSdkVersion', 28)
}

Expand Down
Loading

0 comments on commit 2dd6efe

Please sign in to comment.