Currently I am sending images between an IOS app and Java web service as Strings - is there a better way to do this and if so what method is it - the Strings to represent images are huge and its quite hard to manage.
Thanks
If the image implementation you're using is serializable, serialize it.
I understood that you are currently using BASE64 encoded images being represented as strings, correct?
This approach is reasonable for small binaries/images and also to avoid many individual calls for each image in case of an list of images for example.
Anyway - a proper way would be to use a POST or PUT request to send an image to a Java web service in form of an x-www-form-urlencoded request. This is similar to what you do in a typical upload form.
Look at the example in this answer:
Send image to server as binary data
For the download of an image you can use a GET NSURLRequest (include required headers, authentication or other information to the request) and convert the received NSData to an image.
[UIImage imageWithData:dataReceivedFromURLRequest];
Or directly create the NSData for simple http requests like this and convert it to an image:
NSData *urlData = [NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://my-web-service/image.png"]];
On the server side you could create an image REST endpoint using JAX-RS for example.
Please note that frameworks like AFNetworking help a lot providing convenient ways sending and receiving image/binary data.
Related
Hi i have a requirement to send a daily email to customers with latest information. This weather information is on an image on the message body. The readings on the image will be dynamic. Any pointers on how i can achieve this.
Same image is below
As seen above all the text will change dynamically based on the weather forecast and this has to go as a mail body.
I use java for programming, but i am ok to use any programming language based on suggestion on how this can be archived quickly
You can create inline images within HTML like this: https://en.wikipedia.org/wiki/Data_URI_scheme .
A little more effort is required to create MIME attachments, which you would reference from your HTML. This also results in inline images. How to create an email with embedded images that is compatible with the most mail clients
These are two alternatives for creating a dynamic image at the time of your email's creation. For more dynamic behaviour, you would either use proper image urls (which will be blocked by clients) or you could use Javascript (which should not work for any client for security reasons).
What is the best practice if you are implementing web services that will send and receive large files to/from clients. Normally we are sending JSON objects, but it could be problematic if we include large data payload inside of the JSON objects. We need to provide JSON data as well as a payload, anyone have experience with something similar?
You could embed links to the raw data in your JSON responses. For example:
{
title: 'A Really Big File',
date: '2011-11-11',
file: 'http://example.com/really_big_file.xls'
}
That way you can allow clients to decide whether or not they want to dereference the big file or not.
Base64 is a very inefficient way of doing this, but universal. You could send your files using HTTP Post-request with special parameter "multipart/form-data".
I want to write an application in Java that will communicate with Google App Engine app written in Go by sending and receiving dynamic data. The data is not human readable (as in, not ASCII, Unicode or the like) and ranges from a couple bytes to about 1MB.
I am wondering if it is possible to send such data to and from GAE using Post method directly, or is it better to just encode it as a hex dump and transfer is at text (thusly increasing its size a couple times)?
Yes, this is possible, of course. Just like an HTTP response, an HTTP request can contain a payload of any sort (unless it's a GET or other method that doesn't permit a body); just set the content-type appropriately and send the data in the body of the HTTP request.
If people can POST 10mb photos to Facebook, then I don't see why you can't do that with your data :)
I don't know a lot about this area so please excuse me if my question is vague or stupid.
I have a webpage which uses javascript and AJAX to display live data. Every few seconds, a request is made and a JSON response is returned and the data on the webpage is updated.
What I want to do is create a program in Java that will basically capture every response and interpret the data. I have found libraries which handle the JSON format already. However, I don't know how to get the response using Java.
So for example, a live news feed. I would like to log the data as it appears.
Thanks
Basically what you need to do is make an HTTP GET request to the page that hosts the JSON. You can do this by using a Java HTTP client. The one in the link is from Apache Commons but I believe there is actually one built into Java that is relatively straight-forward to use. When you make a request, it will return a result object that you can then use to access the response data and information such as response headers, etc.
The coding language is Java.
I have a ByteArray embedded in ActionScriptObject.(http://smartfoxserver.com/'>Smartfox Server)
I want to convert it into ByteArray.
The idea is to save it as an image.
This a sequel to the post --> Convert Byte Array from Action Script to Image in Java and save it
Have tried http://www.javafaq.nu/java-article236.html'>this method
It failed with the
java.io.NotSerializable Exception
Regards,
naveenj
The NotSerializableException is because the ActionScriptObject does not implement Serializable.
The ActionScriptObject does not support byte arrays. This is according to information found on the SmartFox Server forum. This probably means that when it creates the Java object that represents your ActionScript object, it does not copy the "arr" property at all!
To transfer the image data to the server you will have to use a network socket and write the data down the wire.
Reading the docs for Smartfox Server, there is a SocketLoader tutorial in chapter 8.17 which should allow you to transmit the image data to the server. http://www.smartfoxserver.com/docs/index.htm?http://www.smartfoxserver.com/docs/docPages/tutorials_pro/17_socketFileLoader/index.htm
Have you tried with JBoss Serialization? http://www.jboss.org/serialization
Regards.