515
Views
12
Comments
Solved
Reactive Web, Check File Type
Question

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

Staff
Rank: #20
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


testUploadExcel.oml

Rank: #384

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

Rank: #218

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

Rank: #218

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

thank you

Rank: #262

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 

Rank: #218

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

Rank: #218

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

thank you

Rank: #218

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

Staff
Rank: #20
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


testUploadExcel.oml

Rank: #218

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

Staff
Rank: #20

Pretty cool! Thanks for sharing.