Reactive Web, Check File Type

hi there, 

how to check content type of uploaded file in reactive web?

I want to check if the file is an xls file.

regards

Hi IBOX,

You can do something like this:

Substr(Upload1.Filename,
Index(Upload1.Filename,".",startIndex:,True,True)+1,
Length(Upload1.Filename)-Index(Upload1.Filename,".",startIndex:,True,True)+1) = "jpg"

OR

Go for this:

https://success.outsystems.com/Documentation/Development_FAQs/How_to_validate_file_input_on_a_File_Upload_Widget_in_a_Web_Application

May this will help you

Regards,

Amreen

Thanks, but it can be cheated, supposed it is not an xls file, but an image file with extension .xls.

I want the true file type like checking in the traditional web, where there is a file.type and i can check like this

:

SyntaxEditor Code Snippet

not (Upload1.Type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" or Upload1.Type="application/vnd.ms-excel")

regards

Amreen wrote:

Hi IBOX,

You can do something like this:

Substr(Upload1.Filename,
Index(Upload1.Filename,".",startIndex:,True,True)+1,
Length(Upload1.Filename)-Index(Upload1.Filename,".",startIndex:,True,True)+1) = "jpg"

OR

Go for this:

https://success.outsystems.com/Documentation/Development_FAQs/How_to_validate_file_input_on_a_File_Upload_Widget_in_a_Web_Application

May this will help you

Regards,

Amreen

the success is for traditional web, i want the reactive web.

regards


How to check in Client Action and how to check in server action?

thank you

You want to check the MIME type of a file on client side, before it gets uploaded? 

In any case, it seems possible with javascript: link 

Thank you Sir,

How to write that JS that refer to Upload widget in the Reactive Web, because we have widget name, file content and file name?

thank you

Or is there a C# extension code to check file type, given its binary?

thank you

Hi IBOX,

In the limit you can create a server-side action that will do that, but that implies sending the file to the server.

Like Tim suggested, the link has all the instructions to check the file type before uploading. You'll need to check the file format that you want to check and the value in the header.

My suggested approach would be a 2 folded approach:

- Client-side, validate with blob or simple the extensition type

- Server-side validate the file type properly

This will enable you to have the best of both worlds without making mobile do heavy work.


Cheers,

RG


IBOX wrote:

Or is there a C# extension code to check file type, given its binary?

thank you



Hi, Ruben, thank you.

But i do not know how to create the JS, and which one is the input widget ID, because it is a Reactive Web.

thank you

Solution

Hi IBOX,

The "accept" extended attribute should make the open file window only ask for xls and xlsx files.


And this is an action that can check on the client side:

But this last one will not protect a lot, as I believe it depend if excel is even installed on customers computers.

As for the server side wouldn't an exception handler on the flow where you are using the ExcelToRecordList be enough (if that is your use case). 

Cheers,

Tiago Simões


Solution

Thank you very much Sir,

The JavaScript  is very nice, and the Excel Trick is good (but if it is excel and the structure is wrong, exception is thrown also).

I also create a component in the forge using c# for server side checking:

https://www.outsystems.com/forge/component-overview/7202/file-type-file-extension

regards

Pretty cool! Thanks for sharing.