How to get the most direct type name of a file

Hi all,I use file upload widget to upload files,I got the type of the file through the widget's type property,but But this is not the latest result I got.like this as follow:

I want to get type like this:png,txt,pdf,docx,pptx,xlsx and more,Is there a third-party function in outsystems to handle it.I was new,thank you everyone!

I don't know if I understood what you want, but when a file is uploaded, the Upload Widget reports the file type in the "Type" Runtime Property. I'm not sure why you need the HTTPRequestHandler for that?

If you just want to accept JPG, PNG and GIF files, you could try the ImageToolbox Forge Component for checking the file's validity.


Cheers,
Nuno Verdasca


This is what I usually do, but it's not heavily tested.

On the IsImage if condition, it's something like extension = "jpg" or extension="jpeg" or extension="png"  

I guess it's not a production code, but it does the trick.




OR


The StackOverflow has a solution that I have used on a mobile app with success:

 


Cheers,

Nuno Verdasca

Nuno Miguel Verdasca wrote:

This is what I usually do, but it's not heavily tested.

On the IsImage if condition, it's something like extension = "jpg" or extension="jpeg" or extension="png"  

I guess it's not a production code, but it does the trick.




OR


The StackOverflow has a solution that I have used on a mobile app with success:

 


Cheers,

Nuno Verdasca

My problem is that the original file type name is too long, and I want to get the short name, such as application / pdf in the picture, and the name I want is pdf, application / vnd.openxmlformats-officedocument.spreadsheetml.sheet (Office Excel File) is xlsx.Is it only by intercepting the file name?


Solution

Hi Yi Wang,

Those file type names are actually the MIME type and they are standard. If you want a user-friendly name, you will have to build your own business logic to map the MIME type to the user-friendly name that you want to display.

You can find the official list here and a more down-to-earth (albeit incomplete) version here (including typical extensions and commonly used names).

Hope this helps.

Solution

Yi Wang wrote:

Nuno Miguel Verdasca wrote:

This is what I usually do, but it's not heavily tested.

On the IsImage if condition, it's something like extension = "jpg" or extension="jpeg" or extension="png"  

I guess it's not a production code, but it does the trick.




OR


The StackOverflow has a solution that I have used on a mobile app with success:

 


Cheers,

Nuno Verdasca

My problem is that the original file type name is too long, and I want to get the short name, such as application / pdf in the picture, and the name I want is pdf, application / vnd.openxmlformats-officedocument.spreadsheetml.sheet (Office Excel File) is xlsx.Is it only by intercepting the file name?



Sorry,

But how can it be too long? There are a gazillion mime-types which can be short and very long.
The examples you have show are all "official" mimetypes (http://www.iana.org/assignments/media-types/media-types.xhtml)
If you want to have the "short" version, you will need to create a mapping table yourself and fill it in with the mappings and you are in business.




J. wrote:

Yi Wang wrote:

Nuno Miguel Verdasca wrote:

This is what I usually do, but it's not heavily tested.

On the IsImage if condition, it's something like extension = "jpg" or extension="jpeg" or extension="png"  

I guess it's not a production code, but it does the trick.




OR


The StackOverflow has a solution that I have used on a mobile app with success:

 


Cheers,

Nuno Verdasca

My problem is that the original file type name is too long, and I want to get the short name, such as application / pdf in the picture, and the name I want is pdf, application / vnd.openxmlformats-officedocument.spreadsheetml.sheet (Office Excel File) is xlsx.Is it only by intercepting the file name?



Sorry,

But how can it be too long? There are a gazillion mime-types which can be short and very long.
The examples you have show are all "official" mimetypes (http://www.iana.org/assignments/media-types/media-types.xhtml)
If you want to have the "short" version, you will need to create a mapping table yourself and fill it in with the mappings and you are in business.



thank you!^_^



Jorge Martins wrote:

Hi Yi Wang,

Those file type names are actually the MIME type and they are standard. If you want a user-friendly name, you will have to build your own business logic to map the MIME type to the user-friendly name that you want to display.

You can find the official list here and a more down-to-earth (albeit incomplete) version here (including typical extensions and commonly used names).

Hope this helps.

thank you!^_^I know how to do it


Nuno Miguel Verdasca wrote:

This is what I usually do, but it's not heavily tested.

On the IsImage if condition, it's something like extension = "jpg" or extension="jpeg" or extension="png"  

I guess it's not a production code, but it does the trick.




OR


The StackOverflow has a solution that I have used on a mobile app with success:

 


Cheers,

Nuno Verdasca

Thank you very much, you helped me many times


Yi Wang wrote:

Nuno Miguel Verdasca wrote:

This is what I usually do, but it's not heavily tested.

On the IsImage if condition, it's something like extension = "jpg" or extension="jpeg" or extension="png"  

I guess it's not a production code, but it does the trick.




OR


The StackOverflow has a solution that I have used on a mobile app with success:

 


Cheers,

Nuno Verdasca

Thank you very much, you helped me many times


You don't have to thank me! =)