wanted to post image from android to WCF rest service - android

I want to upload or post a image file on server using REST WCF. For this I am using JSON as input format.
But when I am checking this post call with debugger due to Base64 image data input is not accepted by the debugger .
I was giving me the 400-Bad Request response for this call.
Thanks.

First understand the concept of JSON/REST.
Then Make your WCF method to input the Byte[] i.e. Byte Array.
Convert your Image in Base64 and Pass it to the REST.
In order to send Image to JSON Web Service, you need to convert that to Byte Array or Base 64 String Representation.
Hope this helps.

Related

Send image via json in android

Hi I am working with android.I want to send an image from server to android and I had done it with sending url from server.How can I send an image from server to android app via json?? is it possible??
It is possible if you can convert your image at your server to a Base64 encoding string. Then you can send the string to your app via JSON.
You can use Apache Common IOUtils:
Base64.encode(FileUtils.readFileToByteArray(imageFile));
On your app you can convert the string to image, example in this link
How to convert a Base64 string into a BitMap image to show it in a ImageView?
Hope that helps
It is possible to send binary data within Json but you have to escape the binary data (UTF-8 encoding and use Base64.) This will increase the data size. Why not just include the path in JSON and fetch/load it?

Android to .NET image transfer using HTTP Get

I have successfully send a string from android to .NET using HTTP GET, I am using WCF in the .NET end, my real intention is to send an image from android mobile to .NET server, can I use GET for this, ie, convert the image into base64 string and then send the image to .NET just like I did for the string? If no, why is it not possible?
GET would append the Base64 encoded string representation of the image to the URL. URLs have length limitations hence the entire string may not get transferred.
A better approach would be to use POST with JSON data to hold the Base64 encoded image string.

Removing special characters in Json while sending to server

hi after computing im getting json as below
{"xxxx":"{\"value\":\"http:\\\/\\\/blaze.mobiclay.net\\\/action\\\/qzproject\\\/feed\\\/20111015\\\/getfeedurl?feedID=702\",\"type\":\"RSS\"}","yyyy":"{\"value\":\"chg\",\"type\":\"String\"}","zzzz (mins)":"{\"value\":\"3\",\"type\":\"String\"}",
but i need it as below when i need to send it to server
{"xxxx":{"type":"RSS","value":""},"zzzz (mins)":{"type":"String","value":""},"yyyy":{"type":"String","value":""}}
I think this is you are looking for:-)
encode
and decode

Android: incomplete soap response?

I make a soap request in my Android app using HttpURLConnection the response is a base64 encoded string holding the data of an image.
the problem is that the response always received in complete. so the image can not be constructed correctly.
what can be the reason for this ?
thanks
A friend of mine blogged about this a year or so ago. Base64 is supposed to be built in, but isn't/wasn't? He has details here.
Possibly server is sending the incorrect Content-Length header.
Did you write the server code?
Happened to me once when I was reporting the content length based on the size of buffer not the actual size of data inside buffer.

Parse simple string JSon in Android

I have the following code:
String response = webService.webGet(""); the response of the web service
String LargeImage = new Gson().fromJson(response,String.class);
byte[] imageByteArray = Base64.decode(LargeImage);
response is like: "iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCA... " a Base64 encoded image having around 400.000 characters.
The response comes very quick from the web service. When it tries to parse it with Gson after a while (like 20-30 seconds) I get an error with out of memory. How can I parse this simple string without Gson, it should be fairly simple but I don't know how to do it.
Please advise me. Thank you for your time
Change your Base64 image encoding into a URL where you can download the image directly.
Then go get flexjson 2.1 and you can parse JSON on Android very easily in a few lines. It's also faster than GSON.
http://flexjson.sourceforge.net
But from your post it looks like you're just sending the Base64 image over JSON as a single string. No need to use JSON in that case. Unless you plan on wrapping some metadata around it in the future.
Also skip storing the image in the DB. Just write it to the filesystem, and put the file path in the DB linked to your object. Much easier to debug when you wonder what image you downloaded, etc.
response is like: "iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCA... " a Base64 encoded image having around 400.000 characters.
You have got to be kidding me.
Please advise me.
Find a sensible Web service and switch to it. If somebody at your firm wrote the Web service, fire them. If you wrote the Web service, fire yourself. I see no need to be returning an image -- particularly one that massive -- in Base64 encoding, wrapped in JSON.
In the meantime, you could try the built-in Android JSON parser rather than Gson.

Categories

Resources