how to validate image jpg or png type not pdf type or other
Hello Bijay,
I have created a small in reactive.
https://personal-xyog61l7.outsystemscloud.com/validationIMAGE/imagedemo?_ts=637762275875707408
Please find the updated OML.
Regards,
Ajit Kurane.
You need to do this.
Get the file size, calculate to MB and then make a condition
Check the OML in these steps
You can test here on this link!
https://marcio-carvalho4.outsystemscloud.com/validationIMAGE/imagedemo?_ts=637762597100759025
Márcio
Can this help you? This post has great answers to validate image jpg or png. You have an example
https://www.outsystems.com/forums/discussion/70062/how-can-add-validation-for-uploading-files/
Or you can use this asset to validate image jpg or png whether it is an image or not.
https://www.outsystems.com/forge/component-overview/7202/file-type-file-extension
You have another solution to see if is an image or not, in this case, you can compare and it says by using the binary data:
https://www.outsystems.com/forums/discussion/75039/how-i-can-check-if-the-binary-data-is-equal-to-image/
Here you have a way to see the file size:
https://www.outsystems.com/forums/discussion/61167/how-to-get-upload-file-size/
Its a lot of topics to put in this answer, please let me know if it helped you :)
Kind Regards,
thank you it was helpful but what i should do about size of the image file validation.image file cant be greater than 1 mb.
Hope you are doing well.
Please add below condition using if widget in your flow,
If(Index(Upload1.Filename,".png")<>-1,True, If(Index(Upload1.Filename,".jpg")<>-1,True,False))
Hope it helps you.
file extensions can (although not common) have any combination of upper and lower case characters, furthermore jpg sometimes are also stores as jpeg. So your logic will not work in all situations. You need to use the optional ignoreCase: True property of the Index function.
Many thanks for your suggestion.
Hi Ajit,
I'd like to add a remark that is completely unrelated to the topic of this post : inside an If widget, there's no need to add an If statement.
i.m.h.o. readability would be improved to have this inside your if widget
Index(Upload1.Filename, ".png", ignoreCase : True) > -1 or Index(Upload1.Filename, ".jpg", ignoreCase : True) > -1 or Index(Upload1.Filename, ".jpeg", ignoreCase : True) > -1
the result of this is already a boolean, so no need to do an If(condition, True, False), that doesn't add anything.
Dorine
but what can i do about the size part.image file cant be greater than 1 mb.