M mehdimf20 Member Licensed User Apr 21, 2018 #1 Hi All, How to get file extension in ContentChooser ? Code: Copy Sub chooser_Result (Success As Boolean, Dir As String, FileName As String) If Success Then Dim m As MLfiles Log(m.GetFileType(FileName)) ' return unknown End If End Sub Last edited: Apr 21, 2018
Hi All, How to get file extension in ContentChooser ? Code: Copy Sub chooser_Result (Success As Boolean, Dir As String, FileName As String) If Success Then Dim m As MLfiles Log(m.GetFileType(FileName)) ' return unknown End If End Sub
DonManfred Expert Licensed User Longtime User Apr 21, 2018 #2 Please use [CODE]code here...[/CODE] tags when posting code. It is not possible in all cases to get the Extension. What do you need it for? You can open the file using the given path and filename anyway. Upvote 0
Please use [CODE]code here...[/CODE] tags when posting code. It is not possible in all cases to get the Extension. What do you need it for? You can open the file using the given path and filename anyway.
M mehdimf20 Member Licensed User Apr 21, 2018 #3 DonManfred said: Please use [CODE]code here...[/CODE] tags when posting code. It is not possible in all cases to get the Extension. What do you need it for? You can open the file using the given path and filename anyway. Click to expand... use this code for get image or video and show image or video. Code: Copy chooser.Show("video/mp4,image/*", "select") Upvote 0
DonManfred said: Please use [CODE]code here...[/CODE] tags when posting code. It is not possible in all cases to get the Extension. What do you need it for? You can open the file using the given path and filename anyway. Click to expand... use this code for get image or video and show image or video. Code: Copy chooser.Show("video/mp4,image/*", "select")
Marcos Alves Well-Known Member Licensed User Longtime User May 26, 2018 #4 DonManfred said: Please use [CODE]code here...[/CODE] tags when posting code. It is not possible in all cases to get the Extension. What do you need it for? You can open the file using the given path and filename anyway. Click to expand... Hi @DonManfred . I have the same problem... answering your question (what do you need it for?), should be: 1. Rotate a JPEG image if needed before loading into imageview... 2. Show a GIF in the correct object, and be able to copy to a .gif extension in internal dir, maintaining the image integrity... 3. Play a video when receiving a mpeg extension... I could list many other causes to know the extension of a file chosen by a content chooser before processing it, but those are my reasons. and so: how can we do that? I think that I could load the file in a byte stream and parse it to find the content types signatures, but for me really looks complicated... must to exist other way... can U help us? Upvote 0
DonManfred said: Please use [CODE]code here...[/CODE] tags when posting code. It is not possible in all cases to get the Extension. What do you need it for? You can open the file using the given path and filename anyway. Click to expand... Hi @DonManfred . I have the same problem... answering your question (what do you need it for?), should be: 1. Rotate a JPEG image if needed before loading into imageview... 2. Show a GIF in the correct object, and be able to copy to a .gif extension in internal dir, maintaining the image integrity... 3. Play a video when receiving a mpeg extension... I could list many other causes to know the extension of a file chosen by a content chooser before processing it, but those are my reasons. and so: how can we do that? I think that I could load the file in a byte stream and parse it to find the content types signatures, but for me really looks complicated... must to exist other way... can U help us?
canalrun Well-Known Member Licensed User Longtime User May 26, 2018 #5 I could list many other causes to know the extension of a file chosen by a content chooser before processing it, but those are my reasons. and so: how can we do that? I think that I could load the file in a byte stream and parse it to find the content types signatures, but for me really looks complicated... must to exist other way... can U help us? Click to expand... The following is a brute force routine I have used in the past to get the file extension: (Note: this is written off the top-of-my-head. There might be some typo's) Code: Copy Sub GetFileExt(FileName As String) as String Return(FileName.SubString2(FileName.LastIndexof("."), FileName.Length) End Sub Barry. Upvote 0
I could list many other causes to know the extension of a file chosen by a content chooser before processing it, but those are my reasons. and so: how can we do that? I think that I could load the file in a byte stream and parse it to find the content types signatures, but for me really looks complicated... must to exist other way... can U help us? Click to expand... The following is a brute force routine I have used in the past to get the file extension: (Note: this is written off the top-of-my-head. There might be some typo's) Code: Copy Sub GetFileExt(FileName As String) as String Return(FileName.SubString2(FileName.LastIndexof("."), FileName.Length) End Sub Barry.
Marcos Alves Well-Known Member Licensed User Longtime User May 26, 2018 #6 canalrun said: The following is a brute force routine I have used in the past to get the file extension: (Note: this is written off the top-of-my-head. There might be some typo's) Code: Copy Sub GetFileExt(FileName As String) as String Return(FileName.SubString2(FileName.LastIndexof("."), FileName.Length) End Sub Barry. Click to expand... Hi, this routine will not work. When came from gallery thru content chooser, filename is an url relative to gallery app and will not have a name with extension. Its something like this: content://media/external/images/media/16 The solution is to get the file, write as bytes with a generic name, parse it and identify the signature of each type (jpeg,mpeg,gif) ... I think that if the content chooser has image/* parameter, it's possible to get gif, jpg or png for example. Like @Erel already told in a post, there is no problem if you copy a png image as jpg BUT if it's a gif? You will loose data of course. And more: jpg image has rotation parameter and sometimes it's needed to rotate before loading on the screen. Then, IF your content chooser is image/* it's really needed to know the extension of source file to proceed the correct image processing. For now, my solution is to separate: image/jpg and image/png from image/gif , with different content choosers/routines in the activity. Upvote 0
canalrun said: The following is a brute force routine I have used in the past to get the file extension: (Note: this is written off the top-of-my-head. There might be some typo's) Code: Copy Sub GetFileExt(FileName As String) as String Return(FileName.SubString2(FileName.LastIndexof("."), FileName.Length) End Sub Barry. Click to expand... Hi, this routine will not work. When came from gallery thru content chooser, filename is an url relative to gallery app and will not have a name with extension. Its something like this: content://media/external/images/media/16 The solution is to get the file, write as bytes with a generic name, parse it and identify the signature of each type (jpeg,mpeg,gif) ... I think that if the content chooser has image/* parameter, it's possible to get gif, jpg or png for example. Like @Erel already told in a post, there is no problem if you copy a png image as jpg BUT if it's a gif? You will loose data of course. And more: jpg image has rotation parameter and sometimes it's needed to rotate before loading on the screen. Then, IF your content chooser is image/* it's really needed to know the extension of source file to proceed the correct image processing. For now, my solution is to separate: image/jpg and image/png from image/gif , with different content choosers/routines in the activity.
canalrun Well-Known Member Licensed User Longtime User May 26, 2018 #7 Marcos Alves said: When came from gallery thru content chooser, filename is an url relative to gallery app and will not have a name with extension. Its something like this: content://media/external/images/media/16 Click to expand... Thanks. Did not realize that the filename had a relative format. This info will come in handy when I need to use the chooser. Barry. Upvote 0
Marcos Alves said: When came from gallery thru content chooser, filename is an url relative to gallery app and will not have a name with extension. Its something like this: content://media/external/images/media/16 Click to expand... Thanks. Did not realize that the filename had a relative format. This info will come in handy when I need to use the chooser. Barry.
stevel05 Expert Licensed User Longtime User May 27, 2018 #8 You could try the code here and see if it will help : https://www.b4x.com/android/forum/threads/simple-image-info-image-size-and-mime-type.91677/ Upvote 0
You could try the code here and see if it will help : https://www.b4x.com/android/forum/threads/simple-image-info-image-size-and-mime-type.91677/
Marcos Alves Well-Known Member Licensed User Longtime User May 27, 2018 #9 stevel05 said: You could try the code here and see if it will help : https://www.b4x.com/android/forum/threads/simple-image-info-image-size-and-mime-type.91677/ Click to expand... thanks. I'll try Upvote 0
stevel05 said: You could try the code here and see if it will help : https://www.b4x.com/android/forum/threads/simple-image-info-image-size-and-mime-type.91677/ Click to expand... thanks. I'll try