Hello Everyone,
How to implement validation on upload widget. In this validation i want to validate file format and file size. if file format is not matches validation file format the preview of image will not show and give us a error message please select image this file format is not supported and also not save the image in database. Please help me out.
Regards,
SSR
Hi Shubham
For file validation, you can use "If" in action and give condition as
"(Substr(FileName,Index(FileName,".",startIndex:,searchFromEnd:,ignoreCase:),7) = ".png")
use "Or" inside if for multiple image formats
i used this method to accept only excel files
I hope it will work for you
Regards
Murali
Hi Murali,
Depending on file extension for file type validation is not a good idea as a file can be renamed. For this, the solution provided by Paulo Zacarias is the correct approach.
Hi SSR,
Here are the details. Please check it.
https://www.outsystems.com/forums/discussion/64358/reactive-webs-upload-widget-validation/
https://success.outsystems.com/documentation/how_to_guides/logic/how_to_validate_file_input_on_a_file_upload_widget_in_a_traditional_web_app/
Thanks,
Ramesh
Hi Shubham,
In order to validate the type of file, I like to use the GetMimeTypes_ByMagicNumbers extension that you can install from the forge:
https://www.outsystems.com/forge/component-overview/6901/getmimetypes-by-magic-numbers
This way, even if your users rename the file extension to trick the system, it won't work. (Example: you have a ".png" file and you change the extension to ".pdf", in this case, using the component above, it will detect that it is a ".png", not a ".pdf".
To check the file size, you have this:
https://success.outsystems.com/Documentation/11/Reference/OutSystems_APIs/BinaryData_API/#BinaryDataSize
Hope this helps,
PZ
I am sharing with you my form UI and OnChange logic please review it and give me an example of it in oml. file. please help me out
Hi Shubham, it will be easier if you can share the OML.
Hello Paulo,
I am unable to share oml with you because the size of my oml is more than 4mb. so sorry for that.
Ragards,
Alright, no worries.
Another best practice to follow is to avoid large modules, like the one you mentioned. You should consider moving some elements to a new one.
For the implementation of the file validation, on the upload action, you can have 2 server actions: one to validate the file type, making use of the GetMimeTypes_ByMagicNumbers extension I mentioned above, and another one for the file size.
For each of them, you can make use of site properties to define the maximum file size and also for the allowed types of uploads.
Hope this helps you.