react-native-documents / document-picker

Document Picker for React Native
https://react-native-documents.github.io/
MIT License
1.35k stars 437 forks source link

[Android] 'size' is negative value for files over 2GB #599

Closed HongSeokJong closed 1 year ago

HongSeokJong commented 1 year ago

Hello! I am not good at English, so I write with the help of a translator. I ask for your understanding 😂

Feature request

In the case of a file larger than 2GB on Android, size is a negative value as a result of DocumentPicker.pick (It works fine on iOS)

Why it is needed

There is a part that selects a file and processes it using the size of the file. It does not work properly when selecting a file larger than 2GB on Android.

Possible implementation

In getMetadata() of DocumentPickerModule.java, FIELD_SIZE is being treated as int. Changing this to treat it as double works fine.

Code sample

Current code

private WritableMap getMetadata(Uri uri) {
  // ...
          if (!cursor.isNull(sizeIndex)) {
            map.putInt(FIELD_SIZE, cursor.getInt(sizeIndex));  // <-- this line!
          } else {
            map.putNull(FIELD_SIZE);
          }
  // ...
}

New code

private WritableMap getMetadata(Uri uri) {
  // ...
          if (!cursor.isNull(sizeIndex)) {
            map.putDouble(FIELD_SIZE, cursor.getDouble(sizeIndex));  // treat as 'double' 🤗
          } else {
            map.putNull(FIELD_SIZE);
          }
  // ...
}