Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 323
ThiTrou Avatar asked Mar 22 '16 12:03

ThiTrou


1 Answers

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.

like image 139
Rohit Arya Avatar answered Sep 22 '22 21:09

Rohit Arya