3862
Views
16
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

2011-08-23 22-04-05
Tiago Simões
Staff
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
2021-10-17 12-36-16
Amreen Shaikh

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

2025-01-09 14-56-57
IQ78

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


2024-02-14 09-44-45
Omar Abd elkefi

Hi sorry if im responding to an old questions, but you should never check file type with file name, attackers can trick the logic by uploading malicious  files and by just changing the EOF name, file will be accepted.

2022-10-18 07-32-49
Randall Jodache Chetty

Thanks for sharing. Works like a charm !

2023-01-25 05-43-21
Murugan S S

Hi @Amreen Shaikh 

While clicking upload Icon there is a explorer, in that explorer i need to show only specific format files  like- PDF only


2025-01-09 14-56-57
IQ78

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

2025-01-09 14-56-57
IQ78

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

thank you

2020-04-17 08-41-30
Tim Timperman

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 

2025-01-09 14-56-57
IQ78

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

2025-01-09 14-56-57
IQ78

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

thank you

2020-08-05 08-52-58
Ruben Goncalves

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



2025-01-09 14-56-57
IQ78

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

2011-08-23 22-04-05
Tiago Simões
Staff
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
2025-01-09 14-56-57
IQ78

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

2011-08-23 22-04-05
Tiago Simões
Staff

Pretty cool! Thanks for sharing. 

UserImage.jpg
Rodolfo Belo

Here's how it worked for me..

I've created a Client Action:

imagem

 

And in it I left it like this:

imagem

 

Code JS: 

let upload = document.getElementById($parameters.UploadWidgetId);
$parameters.ContentType = upload.children[0].files[0].type;

 

And in the assign:

imagem

 

Then, when using the GetContentType action, just assign your widget's id in the parameter: InputWidgetId

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.