Skip to content

An open-source cross-platform alternative to AirDrop

fix(android): handle special case with content uri

Tien Do Nam2a2a38c1712e
diff --git a/app/lib/util/native/content_uri_helper.dart b/app/lib/util/native/content_uri_helper.dart
index 73cdda2f..18245073 100644
--- a/app/lib/util/native/content_uri_helper.dart
+++ b/app/lib/util/native/content_uri_helper.dart
@@ -43,6 +43,10 @@ class ContentUriHelper {
final decoded = Uri.decodeComponent(fileUri);
final withoutBasePath = decoded.replaceFirst(basePath, '');
- return '$folderName$withoutBasePath';
+ if (withoutBasePath.startsWith('/')) {
+ return '$folderName$withoutBasePath';
+ } else {
+ return '$folderName/$withoutBasePath';
+ }
}
}
diff --git a/app/test/unit/util/native/content_uri_helper_test.dart b/app/test/unit/util/native/content_uri_helper_test.dart
index 7690e573..1f91cd6b 100644
--- a/app/test/unit/util/native/content_uri_helper_test.dart
+++ b/app/test/unit/util/native/content_uri_helper_test.dart
@@ -85,5 +85,17 @@ void main() {
'Documents/Test.pdf',
);
});
+
+ test('should return the relative path from the picked file content uri in SD card root', () {
+ expect(
+ ContentUriHelper.guessRelativePathFromPickedFileContentUri(
+ folderContentUri: 'content://com.android.externalstorage.documents/tree/1234-5678%3A',
+ basePath: '1234-5678:',
+ folderName: '1234-5678',
+ uri: 'content://com.android.externalstorage.documents/tree/1234-5678%3A/document/1234-5678%3ATest.pdf',
+ ),
+ '1234-5678/Test.pdf',
+ );
+ });
});
}