Send long string (Base64 encoded image) via HttpGet - android

I'm trying to send an image as a Base64 encoded string to my PHP script via HttpGet, but as I kind of expected I get a 414 URI too large from my server.
Is there a way to post large strings with HttpGet?
Any help is greatly appreciated.

URI limit depends on server settings and its not a good idea to send huge data via Get method. And no, you cant use Post on Get service.
The best would be to alter your webservice to receive Post request and then you may send as long data as you want

when the URI is too large (cause of you are using it to send an image...) all you can do is to try to make it smaller, by compressing it. Or if you have access to the server, increase the limit....
the one way or the other.... use http-post instead of http-get.
you wont have the problem that the size is limited (or if theres a limit, its way bigger then the one from http-get) and i cant believe that sending an image via http-get is usage as intended by the http

Related

Getting image url from json is better or using an encoded image within json?

I have a json from server in which the image urls are send from server but i want to know if i ask my php developer person to send encoded image in json would be a better approch or the former one ?
I want to load the images in listview after that.
Thanks in Advance.
getting url will be better and clean approach.it will make your response compact and image url can be loaded any time you want where if you transmit encoded image it has to be transmitted in network even if you dont want to display at the time.

Passing JSON string in the URL parameters using Spring & Robospice

I am writing a rest client application and the way the server has been set up (beyond my control) is to perform specific filters the query string has a raw json attached as follows:
http://www.someurl.com/api/user?filter=[{"field1":"value1","field2":"value2","field3":"value3"}]
Currently I am using Robospice/Spring to handle the network requests and for regular queries (i.e. no json paramters) it works pretty well. However, whenever I try and process a GET request with the above described url, I keep receiving 500 server error. I tried the same request using This android-async-library, which seems to be able to handle the parameters a little better (200 OK etc). This has lead me to believe the issue is with the way the URL is formed/parsed.
My question is can Spring handle URLs of this format? or if anyone knows the best way to handle/encode it that will be usable for spring?
Yes possibly your url should be encoded especially when you post json in parameters(because of ", :, }, ' notations)
use this for creating your url
String url = Uri.parse("http://youradres.com")
.buildUpon()
.appendQueryParameter("filter", "[{\"field1\":\"value1\",\"field2\":\"value2\",\"field3\":\"value3\"}]")
.build().toString();
It is probably not a good idea. I would pass those values like this:
http://www.someurl.com/api/user?field1=value1&field2=value2&field3=value3
And manage those values on your controller. I think it is more rest-ish. However, going straight to your question. I think the problem is you need to "encode" your URL before you send those values. And then decode it back in your server.
I can not give you code because I don't use Java but this might help you to get on the right track.

How to send image from one device to another in background on Android?

I need a workaround for the following task:
I have a JPG (of whatever) picture on my sd card, and I need to send it to another device in the background. How should I do that?
Best way (in theory) would be via MMS, but after a lof of searching, I can say that there is no official and trustful (and working) way to do that in the background.
Any ideas, samples, even proofs that it can be done are welcomed! All that matters is that a remote device must have access to that image.
if you want the sending to happen in background you could use android beam, but you would have to get both devices cloth together.
And as i am not sure about what u mean by background i can't be sure that thats what you want. :)
First of all you need to create a "Service" in App which will run in background and do all tasks given below. A central PHP Server required for this task. Other device can download that file by the same HTTP request method.
Convert image to base64 string--
How to convert a image into Base64 string?
you can convert byte array to suitable types- string or delimiter(, or .) separated string
Then create a HTTP request--
Make an HTTP request with android
for HTTP request create a url like this - https://www.yoursite.com/post/?code="base64 string goes here"
-Receive data in php file on your server by $_GET global array
$code = $_GET['code']
In php file convert base64 code to original image.
How to decode a base64 string (gif) into image in PHP / HTML
get image from base64 string
Maybe I explained badly my needs. An important thing I missed is that the same person has access to both device. I solved it by uploading the image to google drive.

android and send data to HTTP server

I write app on android which will need to exchange xml data with http server. I wonder what would be the better approach. Send whole file via POST or maybe get all text from file put it on String and then send this String via POST. Is there will be some difference? If yes what is better option?
I would strongly recommend using POST. While sending the file content using GET is theoretically possibly, in some cases you may encounter problems when using URLs over 2000 characters in length. RFC imposes no strict limit, however some clients and servers impose their own limit. Look at this question for more details on this.
With POST this wouldn't apply and you can send (almost) any size data. To send the file, you would still need to read the content of the file and send it as POST parameter though. Again, in reality, most servers will not accept more than just below 2GB, but that's a separate issue.

Android client-server communcation format

I'm building an Android client for a web service that accepts POST data. We're standing on the fence which format to choose for the POST data. According to me, the easiest way is to send it in UrlEncoded format but server side developer thinks JSON is better.
What are the pros and cons of using UrlEncoded / jsonEncoded / bsonEncoded format?
I would avoid xmlencoded data, but what about the others?
The answer to your question greatly depends on what kind of data you're going to send. If your data is mostly string values, numbers and the like, probably JSON would be your best solution.
Avoid url-encoded data, use MultiPart instead -- it takes a bit more work, but it's more secure (url-encoded data it's visible in the server logs) and you may send large files (images?) easily.
If you are sending maps (set of key-value pairs) and arrays, JSON is probably the easiest to work with from a developer standpoint on both client and server. If you need to optimize instead on use bandwidth usage for large set of non-media data, protobuf works well.

Categories

Resources