226
Views
18
Comments
Solved
Image Compression
Question
Application Type
Reactive

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! 


Screenshot 2024-02-06 150714.png
ImageCompressionExercise.oml
2025-12-12 06-45-53
Nandhakumar Sureshbabu
Solution

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.

SizeCompressor.oml
2025-06-22 13-36-04
Hasnain Khalid

Thank you bro

2021-01-04 08-13-48
Toto
 
MVP

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.

2025-12-12 06-45-53
Nandhakumar Sureshbabu

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.

2021-01-04 08-13-48
Toto
 
MVP

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.

2021-01-04 08-13-48
Toto
 
MVP

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).


2025-06-22 13-36-04
Hasnain Khalid

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.

2021-01-04 08-13-48
Toto
 
MVP

Yes, you can modify from the plugin for that.

2021-01-04 08-13-48
Toto
 
MVP

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.

DemoImageCompression.oml
2025-06-22 13-36-04
Hasnain Khalid
2025-06-22 13-36-04
Hasnain Khalid

I have tried this one too using javascript it is still not working. Can you check it . below is the OML file

Javascriptimagecompression.oml
2025-12-12 06-45-53
Nandhakumar Sureshbabu

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.

2025-06-22 13-36-04
Hasnain Khalid

I have tried to use the above forge component but didnt achieve the desire result

2026-01-03 13-44-38
Erwin van Rijsewijk
Champion

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.

2025-06-22 13-36-04
Hasnain Khalid

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

2026-01-03 13-44-38
Erwin van Rijsewijk
Champion


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.

2025-12-12 06-45-53
Nandhakumar Sureshbabu

@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 .

2025-12-12 06-45-53
Nandhakumar Sureshbabu
Solution

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.

SizeCompressor.oml
2025-06-22 13-36-04
Hasnain Khalid

Thank you bro

2021-01-04 08-13-48
Toto
 
MVP

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.

2025-12-12 06-45-53
Nandhakumar Sureshbabu

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.

2021-01-04 08-13-48
Toto
 
MVP

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.

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