Closed Kita2345 closed 2 years ago
That's all right. If it's not possible to extract the MIME type or filename from the HTTP response, we try to extract it from the URL:
Can you still open this file in the gallery?
Can
Pada Kamis, 25 November 2021, Yaroslav Pronin @.***> menulis:
That's all right. If it's not possible to extract the MIME type or filename from the HTTP response, we try to extract it from the URL: [image: 2021-11-24 21-12-30] https://user-images.githubusercontent.com/7840559/143293817-d06f73b5-ad76-4e1c-b7b7-9e0285d69c95.png
Can you still open this file in the gallery?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/TachibanaGeneralLaboratories/download-navi/issues/197#issuecomment-978122406, or unsubscribe https://github.com/notifications/unsubscribe-auth/AU573WTKSOMRD7VXHBRHGIDUNUUSBANCNFSM5IWWOPAQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
-- null
I believe this is normal behavior (given that browsers have similar behavior). This is a site problem. If you think otherwise, feel free to reopen issue.
I'm not sure if it's the right way to do it
diff --git a/app/src/main/java/com/tachibana/downloader/core/utils/DownloadUtils.java b/app/src/main/java/com/tachibana/downloader/core/utils/DownloadUtils.java
index 2756fa7..26fd414 100644
--- a/app/src/main/java/com/tachibana/downloader/core/utils/DownloadUtils.java
+++ b/app/src/main/java/com/tachibana/downloader/core/utils/DownloadUtils.java
@@ -240,6 +240,10 @@ public class DownloadUtils {
* Compare the last segment of the extension against the mime type.
* If there's a mismatch, discard the entire extension.
*/
+ extension = MimeTypeUtils.getExtensionFromMimeType(mimeType);
+ if (extension != null)
+ extension = "." + extension;
+
int lastDotIndex = filename.lastIndexOf('.');
String typeFromExt = MimeTypeUtils.getMimeTypeFromExtension(filename.substring(lastDotIndex + 1));
if (typeFromExt != null && !typeFromExt.equalsIgnoreCase(mimeType)) {
Get the correct file extension
Hmm, this is just a tricky workaround. The problem is located just below:
/*
* Compare the last segment of the extension against the mime type.
* If there's a mismatch, discard the entire extension.
*/
int lastDotIndex = filename.lastIndexOf('.');
String typeFromExt = MimeTypeUtils.getMimeTypeFromExtension(filename.substring(lastDotIndex + 1));
if (typeFromExt != null && !typeFromExt.equalsIgnoreCase(mimeType)) {
...
}
The fact is that MimeTypeMap.getMimeTypeFromExtension
doesn't return the MIME type for .php
extension. In this case, the .php
extension isn't discarded in favor of the correct MIME type extension (image/png
).
@xibr Is there a better option than MimeTypeMap.getMimeTypeFromExtension
? Maybe there are third party libraries? Android Framework seems to not contain a complete set of extensions.
In this case, how about replacing https://github.com/TachibanaGeneralLaboratories/download-navi/blob/a9eede460e4a5cf0eb93f5af5738ae56f55c5d66/app/src/main/java/com/tachibana/downloader/core/utils/MimeTypeUtils.java#L24 and adding MimeTypeMap.java directly to com.tachibana.downloader.core.utils
So we can add MIME type for .php extension in getSingleton()
sMimeTypeMap.loadEntry("application/x-httpd-php", "php");
or any other MIME types not provided by Android Framework.
I don't know if this option is better than third-party libraries, I quickly searched and couldn't find it, I can search again if this solution is not suitable.
@Kita2345 Really nice, I'll see.
@Kita2345
So, I looked at URLConnection.guessContentTypeFromStream
and it turns out that it recognizes very few formats, a small number of common Web image formats, xml and such similar things. I think for now we'll get by with a pre-defined list of MIME types (as suggested by @xibr) that for some reason aren't recognized by extension.
https://github.com/LNReader/lnreader
Pada Jum, 12 Apr 2024 00.26, Kiri gaya @.***> menulis:
Download link is not valid. on google translate page
Steps 1, go to https://translate.google.com/?sl=sv&tl=en&op=docs 2, translate file (pdf for example) 3, click download
can't download exported contacts from https://contacts.google.com/
Downloaded not in .png but in .php file extension.
Link https://www.meteo.pl/um/metco/mgram_pict.php?ntype=0u&row=411&col=207&lang=pl