Preprocess file before Upload

Hi everybody,

is it possible to preprocess file before it is uploaded by Upload component?

Usecase: My users are taking photos with IPad’s camera which I need to send to server.
Problem: Users have IPad with it’s big-resolution camera (1 photo = cca 1MB), but I need to send photos using mobile internet (cca 50KB/s), so it takes too long to transfer file and consumes too much data trafic, there is requirement which says that ideal photo resolution is 1024x768px. So I need to preprocess photo (change resolution) before send it.

Thank you for any suggestions.
Jan Zdrha

Sure, you could use the
library to capture the picture, reduce its size, and then upload it to the server. Both the ImageTransformer and EXIFOrientationNormalizer allow reducing the image size.

The library is documented in the upcoming TouchKit 4 documentation. There’s no HTML version of it anywhere yet, but the DocBook source should be clear enough to read

The library doesn’t require TouchKit, but is of course most suitable with it, and you can nicely use it in offline mode, as is done in the Parking demo.

Thank you for pointing me to that library, it perfectly fit my needs. I created a widget like in the example mentioned. But now I dont know how to use it, on server side I am expecting to use Upload (or do the library provide some custom component?), but how to connect this Upload component with newly created client side widget? Or do I have to create/inherit new component for server side? I am using Vaadin 7 with Touchkit 4.

(little typo in documentation’s example setMaxHeigTH → setMaxHeigHT)

You can send it to the server with ServerRPC. For example in the Parking demo, the image is stored in the
Ticket object
as encoded URL. The tickets are serialized as string and then sent to the server using RPC
in the connector
. Well, persisting the tickets is requested in the
ticket view widget

Well, not sure if you have that complex case, but in any case, you can do it with ServerRPC.

Thanks for noting about the typo.

Yes, my case is much simpler, this seems to me like overkill, at first I think I only have to change client component a little - only add “change resolution” function before sending image to server. Server component’s behavior is same - just accept image. But I have only your response so will give it a try…

The add-on is mainly intended for creating TouchKit applications with offline mode, but it would certainly be nice to have a server-side API for the features in the add-on. At least, to be able to launch the camera capture and then update the images, but certainly server-side methods to define client-side image processing would be useful as well. I don’t know about the future of the add-on.