Skip to content

Commit 33bed40

Browse files
committed
fix(chrome-downloads): added flag to mark as download vs image
1 parent 249f5f0 commit 33bed40

File tree

1 file changed

+45
-21
lines changed

1 file changed

+45
-21
lines changed

src/imagepicker.android.ts

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class UriHelper {
2525
}
2626
// DownloadsProvider
2727
else if (UriHelper.isDownloadsDocument(uri)) {
28-
return UriHelper.getDataColumn(uri, null, null);
28+
return UriHelper.getDataColumn(uri, null, null, true);
2929
}
3030
// MediaProvider
3131
else if (UriHelper.isMediaDocument(uri)) {
@@ -45,7 +45,7 @@ class UriHelper {
4545
let selection = "_id=?";
4646
let selectionArgs = [id];
4747

48-
return UriHelper.getDataColumn(contentUri, selection, selectionArgs);
48+
return UriHelper.getDataColumn(contentUri, selection, selectionArgs, false);
4949
}
5050
}
5151
else {
@@ -62,33 +62,57 @@ class UriHelper {
6262
return undefined;
6363
}
6464

65-
private static getDataColumn(uri: android.net.Uri, selection, selectionArgs) {
65+
private static getDataColumn(uri: android.net.Uri, selection, selectionArgs, isDownload: boolean) {
6666
let cursor = null;
6767
let filePath;
68-
let columns = ["_display_name"];
69-
70-
try {
71-
cursor = this.getContentResolver().query(uri, columns, selection, selectionArgs, null);
72-
if (cursor != null && cursor.moveToFirst()) {
73-
let column_index = cursor.getColumnIndexOrThrow(columns[0]);
74-
filePath = cursor.getString(column_index);
75-
if (filePath) {
76-
const dl = android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DOWNLOADS);
77-
filePath = `${dl}/${filePath}`;
78-
return filePath;
68+
if (isDownload) {
69+
let columns = ["_display_name"];
70+
try {
71+
cursor = this.getContentResolver().query(uri, columns, selection, selectionArgs, null);
72+
if (cursor != null && cursor.moveToFirst()) {
73+
let column_index = cursor.getColumnIndexOrThrow(columns[0]);
74+
filePath = cursor.getString(column_index);
75+
if (filePath) {
76+
const dl = android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DOWNLOADS);
77+
filePath = `${dl}/${filePath}`;
78+
return filePath;
79+
}
80+
}
81+
}
82+
catch (e) {
83+
console.log(e);
84+
}
85+
finally {
86+
if (cursor) {
87+
cursor.close();
7988
}
8089
}
8190
}
82-
catch (e) {
83-
console.log(e);
84-
}
85-
finally {
86-
if (cursor) {
87-
cursor.close();
91+
else {
92+
let columns = [android.provider.MediaStore.MediaColumns.DATA];
93+
let filePath;
94+
95+
try {
96+
cursor = this.getContentResolver().query(uri, columns, selection, selectionArgs, null);
97+
if (cursor != null && cursor.moveToFirst()) {
98+
let column_index = cursor.getColumnIndexOrThrow(columns[0]);
99+
filePath = cursor.getString(column_index);
100+
if (filePath) {
101+
return filePath;
102+
}
103+
}
104+
}
105+
catch (e) {
106+
console.log(e);
107+
}
108+
finally {
109+
if (cursor) {
110+
cursor.close();
111+
}
88112
}
89113
}
90-
91114
return undefined;
115+
92116
}
93117

94118
private static isExternalStorageDocument(uri: android.net.Uri) {

0 commit comments

Comments
 (0)