12-07-2009 02:43 PM
This is more of a server side question, but I wanted to what see what the BB "best practice" is, and how the experts are handling this scenario.
I am planning to use servlets to serve data via HTTP to my BB application. I need to retrieve a list of images plus the associated name, description, dates, etc. To sent an image from the servlet, I know I can just send it as a byte array and the BB can read it from http input stream. What about sending the image and the data? How can I separate the bytes of the image from the bytes of the data. Can I send a collection consisting of images and associated data?
What is the best way to approach this?
Solved! Go to Solution.
12-07-2009 04:10 PM - edited 12-07-2009 04:10 PM
In my experience, I get the data as one operation, which includes the URL's to the images.
I then queue up separate GET requests (from the client) for each image.
This allows me to run the image downloads "in background" while I display the list, the update the view when the image data is retrieved.
12-07-2009 04:39 PM - edited 12-07-2009 04:45 PM
Thanks RexDoug, for your feedback.
What would you suggest as a data transfer method? Would it be a better to send it as a stream of XML or a stream of delimited string?
Would you suggest that data be transferred via a serialized object?
12-07-2009 06:16 PM
I agree with RexDoug's general approach.
Regarding how you package your data, are you talking about the image or your data or both?
I don't actually think there is a right answer to your question, and you will get different answers from different people on this forum. marchywka for example woul dprobably suggest sending delimited strings, whereas i prefer XML, though the overhead can be quite hig. I beleive that JSON is much more efficient in terms of payload compared with overhead. Serialising an object could work, but I think XML and JSON are more flexible than that and delimited stream.
12-07-2009 06:22 PM - edited 12-07-2009 06:23 PM
I would answer the question by asking "what does your server-side infrastructure look like?"
If it's dot-net, then you are probably going to want to take the path of least resistance and use JSR 172 or KSOAP.
If you have more flexibility on the server, I would recommend XML or JSON (as Peter says). JSON is going to be more compact, but the BB JSON tools are a little sparse.
On the other hand, the SAX parser libraries on the BB are pretty good for XML.
I would say that in every project I ever worked on, I worked around the foibles of the server infrastructure, rather than the other way around.
12-07-2009 06:23 PM
I was referring to packaging the data. As for the image, I assume I can just stream it as a byte array (unless there is a better approach?).
Thank you both Peter and RexDoug for your feedback!
12-07-2009 07:07 PM - edited 12-07-2009 07:14 PM
Excellent answer RexDoug, which I could have put it that well.
Re image data, byte array, is fine. However if you are attempting to send it as XML data or as POST data, then you will probably need Base64 encoding, then I think there are some characters that need to be escaped for XML or you need URL encoding for the same reason. Sorry not an area on I am strong on, I just do what the Server boys tell me to do.....