Skip to content Skip to sidebar Skip to footer

Android Connection With Mysql Using Json

JSON-MYSQL connectivity with 2 text fields [name and comments] in a mysql table named 'emp' in my server .. and it woks fine ..but now I want to store image , with an extra field..

Solution 1:

Follow the steps to send image from Android to Server

If you want to send image via JSON then you need to convert it to string because JSON doesn't transfer Image directly

Android

STEP 1 : Convert your image in to String using Base64[ Which encodes the image to a string]

STEP 2 : Pass the converted string in JSON.

JSONObject json = newJSONObject(); 
json.put("name", nm);
json.put("comments", com);
json.put("image",convertedString);

In Server Side

STEP 1 Receive the JSON String.($yourimageString)

STEP 2 Decode the JSON string to image using base64_decode ($yourimageString) method.

STEP 3 Now write this in to file. You will get your image now.

Hope it helps.

Post a Comment for "Android Connection With Mysql Using Json"