Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MediaType中的getFileMediaType发现了一个BUG #503

Open
Vaker-new opened this issue Jul 7, 2023 · 0 comments
Open

MediaType中的getFileMediaType发现了一个BUG #503

Vaker-new opened this issue Jul 7, 2023 · 0 comments

Comments

@Vaker-new
Copy link

Vaker-new commented Jul 7, 2023

    public static MediaType getFileMediaType(String fileName) {
        String extension = getUrlExtension(fileName);
        if (!MimeTypeMap.getSingleton().hasExtension(extension)) {
            if (TextUtils.equals("json", extension)) {
                return MediaType.APPLICATION_JSON;
            }
            return MediaType.APPLICATION_OCTET_STREAM;
        }

        String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
        try {
            return MediaType.parseMediaType(mimeType);
        } catch (Exception e) {
            return MediaType.APPLICATION_OCTET_STREAM;
        }
    }

这个方法中的MimeTypeMap.getSingleton().hasExtension(extension)当extension为json是在android9以下设备上返回的是false,在android9以上设备上返回的是true,导致android9一下设备对于.json文件返回的contentType不对,正常应当返回application/json,实际返回了application/octet-stream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants