Hello everyone,
I'm curious to know if it's possible to compress any uploaded image. In other words, if I upload a 2MB image, is it possible to save it in the database after compressing it to a size of, let's say, 200KB? I've experimented with various Forge components, but unfortunately, haven't achieved success. I'd appreciate any insights or recommendations.
can someone please make adjustment in the given OML
Thank you!
Hi @Hasnain Khalid,
I've replicated according to your expectation. But there is some limitation that it's compressing initially but once the file size gets saturated the file size is not getting reduced further. Attached the OML file for your reference.
Hope it helps,Nandhakumar S.
Thank you bro
Careful when using this solution (specially if the bandwidth is limited).
This will send the image (full size) to the server to validate using service action ImageLosslessCompress, then return the image data back to the client, then revalidate again (and if the size still bigger than 200KB, will repeat the process above).
This will bring data back and forth from client to server side.
Yes the function is correct, but the data flow is not the best practice.
Hi @Toto,
I've already warned about this and provided alternative suggestion also in the above Comment. But anyhow, the marked solution is what his expectation is.Cheers,NK.
Hi @Nandhakumar S ,
Yes, I'm not challenging your answer, just to make clear of this data flow that not best practice in term of data movement.
Hi,
You can use this plugin (https://www.outsystems.com/forge/component-overview/13624/resize-image-size) and specify the size that you want (200KB).
I would like to implement a client action that triggers after uploading an image. I want to include an 'if' condition to check if the image size exceeds 200KB. If it does, I intend to reduce the image size and store the compressed version (Size of the compressed image as well) in the database.
Yes, you can modify from the plugin for that.
This is the example.
This also need plugin (https://www.outsystems.com/forge/component-overview/3242/binarydata-client-side) because I assume you want to do this on client side and not on server side.
okay i will try
I have tried this one too using javascript it is still not working. Can you check it . below is the OML file
Hi @Hasnain Khalid,On the Onclick of the upload button, check the size of the respective binary file by using the BinaryDataSize server action.
In the if condition, check size of the file (which will be returned by the server action in bytes). If the size is less than 200kb proceed with your respective logic. If the size exceeds 200kb then compress the file size and proceed with the flow. For compress the file size you can you the plugin, mentioned above.Hope it helps,NandhaKumar S.
I have tried to use the above forge component but didnt achieve the desire result
What kind of image are you uploading? A lot of imageformats e.g. JPG are already compressed, so compressing it a gain will not result in a smaller file.
I'm trying to upload the different images in different format . Irrespective of the format all i want is to check the condition if the size is more than 200Kb then whatever the size of the image above 200Kb should be reduced and store in the database under 200kb
I think you cannot force that the result will be under 200kb. It will be compressed as small as it can be, if you upload a huge file it still can result in a file bigger then 200kb. So maybe you also have to prevent uploading files bigger then "some" size.
@Hasnain Khalid, Erwins idea is a good approach. You validate the file size by using the same server action (BinaryDataSize) which I've mention above .
okay thank you