How to have a webblock to upload a File 

How to have a webblock to upload a File 

i what to need to make a input file widget working but i don't know how.

I there any tutorial or explanation how to get this done?

Hi Nuno,

Well, there isn't a specific tutorial for that.

However, the way to do it is:

1 - Create an entity with a Binary Data attribute, for you to store the file - let's assume the Entity is "File", and has two attributes: Id and Content (which is Binary Data);
2 - Use an Input Filename widget in your web screen.
3 - Have a Submit button in your screen, that executes a screen action. The action should have:
   - a local variable TempFile (for instance), of Record data type, and of the "File" Record definition;
   - an Assign node, that will assign the Input Filename widget's Binary content to the File.Content attribute;
   - a CreateFile entity action, that will store it in the database;

I hope this helps.

Let us know how it goes.


Paulo Tavares
Hi Paulo -

I'm trying to create a very simple document management section in my application, but cannot get the file uploaded correctly.

I read your steps, but do not understand what you mean when you say to create an assign node that will assign the input filename widget's binary content to the entity's content attribute.

What are the settings for the Assign action? Could you provide more detailed steps?

Hi Nick,

Based on the explanation of Paulo, i did a picture to ilustrate these situation.

Let us know if you have any question.
I hope I've helped you.
Nelson Baptista
Wow, talk about full service; thanks for the visual!

I followed all of the steps, but when I try to download the file, it's always 0 bytes.

How does the Create entity action obtain the binary data from the TempFile variable to store in the database?



I managed to assign the contents of TempFile.File.Content to the edit record widget that I'm using to upload the file and that did the trick. Now when I download the file, the file size is correct, but the file doesn't have the file extension. Any ideas?
Nick "Wow, talk about full service; thanks for the visual!"

Outsystems support, is always like this, they always draw a nice picture, and write you a very detailed explaination on how to basically do everything! :)
Hi Nick,

in the download node you have to specify the name of the file plus the extension, like: "document.docx", my advice is to add a field on your entity that stores the extension (usefull for further filters for example).

To get the proper extension from the filename of the input upload file widget i usualy do something like this: 
Substr(UploadWidget.Filename, Length(UploadWidget.Filename)-4 ,Length(UploadWidget.Filename)-1 )
this will return the ".doc", after get this stored as i said.

Then when downloading you just need to create the proper filename + extension with the information you have.

Miguel Antunes

That worked like a charm, but only for files with a 3 digit extention. (.txt) If I use a file with a 4 digit extension (.docx) it does not capture the period, only "docx".

Any ideas?

Thank you!
Hi Nick,

this will just do what you want!
Substr(Filename, Index(Filename,".",Length(Filename)-1,True,True) ,Length(Filename)-1 )
we do a "." search from the end to the beggining to know the start index of it and then voilá ;)

but the downside of this approach is that i'm not sure if it works on versions bellow 6.0.

tell us if you are using a lower version then 6.0, so we can find another solution.

Miguel Antunes

I'm using 5.1.X

If you're using 5.1,.... You should upgrade to 6.0 :)

I tried, but 6.0 doesn't support the community license that I'm using which allows me75,000 SU.
Hi Nick, 

6.0 also includes the comunity license. By default it comes with a 30 days trial and 300.000 SUs and after that you can do the upgrade to the community back to 30.000.

You can check out here


@Robert ... good answers aren't just given by OutSystems Support (there are several OutSystems team members participating, from support, marketing, product management, r&d, professional services...), the others are given by partners, freelancers and of course OutSystems community "geek lovers", and that is what it makes this community so special. 
Hi Nick,

since you dont have the 6.0 ( you should use it, its amazing! :D ), just use the action 'Path_GetExtension' that is in Filesystem extension.

It will do what you want, apart from files with double extension like: filename.tar.gz but that is also a problem in the other approach i've mention before. 

Apart from that, this will move you on!

Miguel Antunes
Thank you... I got it...