|
2 | 2 |
|
3 | 3 | import android.content.res.AssetFileDescriptor;
|
4 | 4 | import android.content.res.AssetManager;
|
| 5 | +import android.database.Cursor; |
5 | 6 | import android.net.Uri;
|
6 | 7 | import android.os.Environment;
|
7 | 8 | import android.os.StatFs;
|
| 9 | +import android.provider.MediaStore; |
8 | 10 | import android.support.annotation.Nullable;
|
9 | 11 | import android.util.Base64;
|
10 | 12 | import android.util.SparseArray;
|
@@ -72,6 +74,21 @@ private Uri getFileUri(String filepath) throws IORejectionException {
|
72 | 74 | return uri;
|
73 | 75 | }
|
74 | 76 |
|
| 77 | + private String getOriginalFilepath(String filepath) throws IORejectionException { |
| 78 | + Uri uri = getFileUri(filepath); |
| 79 | + String originalFilepath = ""; |
| 80 | + if (uri.getScheme().equals("content")) { |
| 81 | + try { |
| 82 | + Cursor cursor = reactContext.getContentResolver().query(uri, null, null, null, null); |
| 83 | + if (cursor.moveToFirst()) { |
| 84 | + originalFilepath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)); |
| 85 | + } |
| 86 | + } catch (IllegalArgumentException ignored) { |
| 87 | + } |
| 88 | + } |
| 89 | + return originalFilepath; |
| 90 | + } |
| 91 | + |
75 | 92 | private InputStream getInputStream(String filepath) throws IORejectionException {
|
76 | 93 | Uri uri = getFileUri(filepath);
|
77 | 94 | InputStream stream;
|
@@ -510,16 +527,17 @@ public void setReadable(String filepath, Boolean readable, Boolean ownerOnly, Pr
|
510 | 527 | @ReactMethod
|
511 | 528 | public void stat(String filepath, Promise promise) {
|
512 | 529 | try {
|
513 |
| - File file = new File(filepath); |
| 530 | + String originalFilepath = getOriginalFilepath(filepath); |
| 531 | + File file = new File(originalFilepath); |
514 | 532 |
|
515 | 533 | if (!file.exists()) throw new Exception("File does not exist");
|
516 | 534 |
|
517 | 535 | WritableMap statMap = Arguments.createMap();
|
518 |
| - |
519 | 536 | statMap.putInt("ctime", (int) (file.lastModified() / 1000));
|
520 | 537 | statMap.putInt("mtime", (int) (file.lastModified() / 1000));
|
521 | 538 | statMap.putInt("size", (int) file.length());
|
522 | 539 | statMap.putInt("type", file.isDirectory() ? 1 : 0);
|
| 540 | + statMap.putString("originalFilepath", originalFilepath); |
523 | 541 |
|
524 | 542 | promise.resolve(statMap);
|
525 | 543 | } catch (Exception ex) {
|
|
0 commit comments