Android Question Detect extension from mime type

Blue.Sky

Active Member
Licensed User
Longtime User
Hi
I download file from url example www.downloadfile.com/download.php?id=1
Now
The filename of ID 1 is b4a.pdf that return in headers
I get headers in JobDone
But i cannot detect extension from mime type for save file.
Notice : I can get content-type but cannot detect extension
Thanks
 

TorontoJim

Member
Licensed User
Longtime User
I know this is an old post but there was no answer, and I'm glad to be able to finally contribute :)

I had to get the extension for a project I'm working on, here is how I did it. Since you are getting the file name, you can grab the extension from that:

B4X:
Sub MyNiftyMethod
    ...process stuff...
    Dim strFileName As String = "something.pdf"
    Dim strExtension As String = GetExtension(strFileName)
    Log(strExtension)
    'prints out: pdf
End Sub

Sub GetExtension(strFileName As String) As String
	If strFileName.IndexOf(".") > 0 Then
		Dim parts() As String = Regex.Split("\.", strFileName)
		Return parts(parts.Length - 1)
	Else
		Return Null
	End If
End Sub
 
Upvote 0
Top