Created
January 21, 2019 06:28
-
-
Save umpteenthdev/c9829a960cbda6a9dcb58a4eea54e3fe to your computer and use it in GitHub Desktop.
How to get MimeType and file extension from byte array on Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.webkit.MimeTypeMap | |
| import java.net.URLConnection | |
| fun getFileInfo(bytes: ByteArray): Pair<String?, String?> { | |
| val mime = URLConnection.guessContentTypeFromStream(bytes.inputStream()) | |
| val extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mime) | |
| return mime to extension | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment