What can we put as parameter of okhttp3 MediaType.parse method for an audio file?
Asked Answered
M

1

9

I found that for uploading images using Android with a RequestBody, we can use MediaType.parse("image/jpeg").

However, what would be the parameter for an audio file ?

Thank you in advance for your answer.

Miramirabeau answered 22/3, 2016 at 12:46 Comment(0)
K
12

You can get mime type of any file using this method:

public static String getMimeType(String url) {
     String type = null;
     String extension = MimeTypeMap.getFileExtensionFromUrl(url);
     if (extension != null) {
        type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
     }
     return type;
}

To get mime, call String mime = getMimeType(file.getAbsolutePath());

You can find list of all mimes here. And thus, mime for audio will be audio/mpeg. But I will still recommend using getMimeTypeFromExtension than hardcoding the value.

Kelsi answered 22/3, 2016 at 13:41 Comment(1)
why does MimeTypeMap.getFileExtensionFromUrl(url) return nothing?Azpurua

© 2022 - 2024 — McMap. All rights reserved.