@@ -34,15 +34,29 @@ internal class IONFLTRFileHelper(val contentResolver: ContentResolver) {
3434 FileToUploadInfo (fileName, fileSize, inputStream)
3535 }
3636 } else {
37- val filePathWithoutPrefix = filePath.removePrefix( " file:// " )
38- val fileObject = File (filePathWithoutPrefix )
37+ val cleanFilePath = normalizeFilePath(filePath )
38+ val fileObject = File (cleanFilePath )
3939 if (! fileObject.exists()) {
4040 throw IONFLTRException .FileDoesNotExist ()
4141 }
4242 FileToUploadInfo (fileObject.name, fileObject.length(), FileInputStream (fileObject))
4343 }
4444 }
4545
46+ /* *
47+ * Normalizes a file path by removing URI prefixes like "file://", "file:/", etc.
48+ *
49+ * @param filePath The file path that might contain URI prefixes
50+ * @return Cleaned file path without URI prefixes
51+ */
52+ fun normalizeFilePath (filePath : String ): String {
53+ return when {
54+ filePath.startsWith(" file://" ) -> filePath.removePrefix(" file://" )
55+ filePath.startsWith(" file:/" ) -> filePath.removePrefix(" file:/" )
56+ filePath.startsWith(" file:" ) -> filePath.removePrefix(" file:" )
57+ else -> filePath
58+ }
59+ }
4660
4761 /* *
4862 * Gets a MIME type based on the provided file path
@@ -51,8 +65,10 @@ internal class IONFLTRFileHelper(val contentResolver: ContentResolver) {
5165 * @return The MIME type or null if it was unable to determine
5266 */
5367 fun getMimeType (filePath : String? ): String? =
54- MimeTypeMap .getFileExtensionFromUrl(filePath)?.let { extension ->
55- MimeTypeMap .getSingleton().getMimeTypeFromExtension(extension)
68+ filePath?.let { normalizeFilePath(it) }?.let { normalizedPath ->
69+ MimeTypeMap .getFileExtensionFromUrl(normalizedPath)?.let { extension ->
70+ MimeTypeMap .getSingleton().getMimeTypeFromExtension(extension)
71+ }
5672 }
5773
5874 /* *
0 commit comments