Skip to content

Commit

Permalink
fix download file name
Browse files Browse the repository at this point in the history
  • Loading branch information
plateaukao committed Mar 18, 2021
1 parent 66be7a9 commit c0c0c73
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/src/main/java/de/baumann/browser/unit/BrowserUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,15 @@ public static void printTimestamp(String function) {
private static String guessFilename(final String url, final String contentDisposition, final String mimeType) {
final String prefix = "filename*=utf-8''";
final String decodedContentDescription = URLDecoder.decode(contentDisposition);
if (decodedContentDescription.toLowerCase().contains("filename*=utf-8''")) {
if (decodedContentDescription.toLowerCase().contains(prefix)) {
int index = decodedContentDescription.toLowerCase().indexOf(prefix);
return decodedContentDescription.substring(index + prefix.length());
}
final String anotherPrefix = "filename=\"";
if (contentDisposition.contains(anotherPrefix)) {
int index = contentDisposition.indexOf(anotherPrefix);
return contentDisposition.substring(index + anotherPrefix.length(), contentDisposition.length() - 1);
}

return URLUtil.guessFileName(url, contentDisposition, mimeType);
}
Expand Down

0 comments on commit c0c0c73

Please sign in to comment.