RestAPI passing images as base64 strings in POST request - android

I'm building a RestAPI for a mobile application where you can upload images and stuff.
My question was about how you pass actual images to the RestAPI.
My design is:
You have an endpoint /api/data/createReport
This endpoint accepts a field called images which is a comma-separated list of strings, which are the base64 encoded images.
I would then split the strings and store them somewhere (or maybe re-encode them as images).
Is this a good design?Is it safe?Is it performant?
Thanks in advance!

Related

Is it possible to send array of image through volley

Is is possible to send array of images using volley library in android.
e.g
param.put("images", arrayOfImages);
Please response as soon as possible.
Yes you can convert the images in base64 strings and send that array of strings using
param.put("images", arrayOfImages);

Download the image by url , or convert it with base64

My app receive a jsonArray that contain names of categories and their images urls. which is the best to do:
send the url of the images and after that download them.
or instead of sending the url I will send the images converted with base64.
actually I know that base64 is more larger, but I just want to do a trade off between the size and the number of the requests, I mean which is better: to get one large request, or get a lot of small request ?
I have about 20 categories and the image is just 20-30 Kb.
1: Send the image urls and download and heavily cache device side, this tends to 'Always' be the best way.
The JSON response should have an array of your objects each with a name and a URL, simply get the JSON response in your app and parse out the relevant URLS and names, downloading each using Picasso (As discussed in earlier question) as you go, it will cache them for faster access in future also.

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.

How to upload image from Android device to Rails server?

I am working on a Android project and want to upload Bitmap images to my rails server. But I have no idea how to write the Rails models or controllers.
I find someone using MultipartEntity post to upload images and paperclip to recieve images on RoR server. I want to know how to connect the post and server (what url?) and how to write the model or controller.
I use a stupid method. I convert the Bitmap image to byte array and use Base64 method to convert it to a string. Post the string to server. When I want to get image, download the string and convert it to Bitmap.

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