Status Update
Comments
vi...@google.com <vi...@google.com> #2
da...@gmail.com <da...@gmail.com> #3
Great! Thanks a lot, I'll look for the live updates soon!
vi...@google.com <vi...@google.com>
av...@google.com <av...@google.com> #4
I am not familiar with this particular API and what might have changed between API 34 and API 35. pbirk@, can you provide some guidance here?
pb...@google.com <pb...@google.com> #5
Hi,
Thank you for the report.
The implementation was indeed changed in API version 35 in order to parse filename*
directives from the Content-Disposition
header.
As part of this change, the method also changed how it handles situations where there is a difference between the extension of the filename found in the Content-Disposition
header string, and the extension suggested by the mimeType parameter.
In previous versions of Android, the method would replace the extension, whereas in 35, it should append the extension suggested by the mimeType parameter.
It seems that there are actually 2 separate but overlapping bugs here:
- We should not append an extension for
application/octet-stream
- We seem to be replacing rather than appending the replacement extension
You can solve the problem in the short term by passing null
instead of "application/octet-stream"
as the mimeType parameter. That will disable any suggestion of extension and use the filename from the header.
If all you want is to parse the Content-Disposition
header and get a filename, then you can also use androidx.webkit
library.
pb...@google.com <pb...@google.com> #6
Hi,
I have looked further into this.
While there is a bug here, it has to do with the fact that the new behaviour is not enabled. I have filed a separate bug to address that problem.
The reason that you are actually seeing a change in API 35 is that a mime-type mapping for the .apkg
extension was added, namely application/vnd.anki
. This results in the function realising that the apkg
extension doesn't match the mime type that you have provided, in which case it will prefer the mime type extension.
So the function is working as documented here.
I suggest one of the following options to fix the issue:
- Use the correct mime-type for the file extension:
application/vnd.anki
. - Use
null
for the mime type if you don't want the method to suggest an extension based on mime-type and always use the filename. - Use
From theURLUtilCompat.getFilenameFromContentDisposition androidx.webkit
library to parse theContent-Disposition
header value without trying to guess a filename from the URL or mime type.
da...@gmail.com <da...@gmail.com> #7
We should not append an extension for
application/octet-stream
The above problem stated in apk downloaded as bin
for example
- Servers aren't required to serve
apk
files with a URL containing the.apk
extension apk
should beapplication/vnd.android.package-archive
, but since API 30,guessFileName
rejects the.apk
extension served withapplication/octet-stream
and replaces it with.bin
- Many Android download managers are expecting
guessFileName
to make a reasonable guess usingcontentDisposition
From the URLUtil.guessFileName
documentation:
File extension, if not defined, is added based on the mimetype. ... If the suggested file type extension doesn't match the passed mimeType, the method will append the appropriate extension instead of replacing the current extension.
The suggested file type extension does match application/octet-stream
: it's a generic MIME type and should match all binary data. It doesn't just match .bin
, and should act similarly to null
.
The "octet-stream" subtype is used to indicate that a body contains arbitrary binary data. ... RFC 1341 also defined the use of a "NAME" parameter which gave a suggested file name to be used if the data were to be written to a file. This has been deprecated in anticipation of a separate Content-Disposition header field, to be defined in a subsequent RFC.
--
Code for context:
See also: MimeTypeMap.remapGenericMimeType
, which does the right thing
pb...@google.com <pb...@google.com> #8
Thank you for feedback, reopening.
The MimeTypeMap.remapGenericMimeType is not part of the public Android API.
That said, I accept your argument that we shouldn't do any remapping for application/octet-stream
specifically.
ap...@google.com <ap...@google.com> #9
Project: platform/frameworks/support
Branch: androidx-main
Author: Peter Birk Pakkenberg <
Link:
Change mimetype handling of guessFileName
Expand for full commit details
Change mimetype handling of guessFileName
If the derived file name already contains a filename, it is likely to be
more correct than the MimeType suggested extension.
Bug: 382864232
Test: Updated URLUtilCompatTest
RelNote: """Change behavior of `URLUtilCompat.guessFileName` to only use
the `mimeType` parameter to suggest an extension for filenames
derived from the URL parameter."""
Change-Id: I53ecd6d664efe5747a4451171617a2d33cfb59eb
Files:
- M
webkit/integration-tests/instrumentation/src/androidTest/java/androidx/webkit/URLUtilCompatTest.java
- M
webkit/webkit/src/main/java/androidx/webkit/URLUtilCompat.java
Hash: 1a38b92d94c64f737497a99a5a1784064891e7db
Date: Wed Dec 18 11:36:05 2024
Description
In API 35,
URLUtil.guessFileName
ignores the file name specified incontentDisposition
and instead produces.bin
forapplication/octet-stream
API 34 returns as expected