About JavaScript Components and client side RPC

Dea Vaadin super client side Gurus.

I am wondering if it is possible from a javascript RPC call to vaadin server side to have both « data » and a « file attachement » to upload.
The case I’m dealing with is a “commenting system” where we want to add a comment and have the possibility to attach a file to this comment (like in facebook) and then save both comment and file at the same time.

This commenting feature muste be done in Javascript (within a Vaadin application) and I am trying to see if it would be feasible to send the attachement at the same time as the comment with a Javascript RPC.

In the book it is mentionned here https://vaadin.com/book/-/page/gwt.rpc.html that :
[font=arial]


You can pass the most common standard Java types, such as primitive and boxed primitive types,String, and arrays and some collections (List, Set, and Map) of the supported types. Also the VaadinConnector and some special internal types can be passed
.

Could the attachement be passed as an array of byte or something like this from the javascript ?
[/font]

The RPC mechanism supports converting between byte on the Java side and an array of JS numbers on the JavaScript side, but it would not be the most efficient approach since the array would be transmitted as a JSON string. It would use 2-4 bytes of data for every byte in the attachment (one comma and 1-3 digits for the byte value), giving several hundred percents of overhead.

If you want to send the attachment data together with the comment instead of sending the attachment as a conventional http upload, I would suggest base64-encoding the data and sending it over the RPC mechanism as a string instead. With this approach, the overhead would be about 25% compared to directly sending binary data.