Reputation: 13
I am new in Android development i just wanted to know how to send image through android REST web services and save it and retrieve from MySQL database
Upvotes: 0
Views: 6192
Reputation: 5030
You can encode Bitmap image to Base64, so you will have an image encoded as string. You can use your REST API to send and save that string to database. Later when you want to display it, download and decode it to Bitmap again. Here is how you can do encoding/decoding.
Upvotes: 0
Reputation: 9935
My experience, client send the image-string
(encoded Image byte array) to server and save it into the database.
To show the image, client get image-string
from server and decoded image-string
to byte array. Try to show image byte array
.
public static String encodeImage(byte[] imageByteArray) {
return Base64.encodeBase64URLSafeString(imageByteArray);
}
public static byte[] decodeImage(String imageDataString) {
return Base64.decodeBase64(imageDataString);
}
Use org.apache.commons.codec.binary.Base64
Upvotes: 1