How To Upload Long Blob (image) To Mysql Database Using Java And Retrieve In Php?
I am working on a project where I need to upload images to the database and retrieve the same from database. I need the image to be uploaded from an android device using java. Here
Solution 1:
/**
*Get profile_pic*/
public function callmethod($userId){
$stmt = $this->conn->prepare("SELECT profile_pic FROM users WHERE unique_id=?");
$stmt->bind_param('s',$userId);
//$result = mysql_query($query) or die(mysql_error());
//$photo = mysql_fetch_array($result);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($profile_pic);
while ($stmt->fetch()) {
echo "<img src='data:image/jpeg;base64,".$profile_pic."' />";
}
//$obj->picture = base64_encode($profile_pic);
//echo $obj;
}
ok try this code this.you don't need
header("Content-Type: image/jpeg");
function. this are error in your php code. this code will create img tag with basc64.
now for android part.
change this in php.
while ($stmt->fetch()) {
echo "<img src='data:image/jpeg;base64,".$profile_pic."' />";
}
to
while ($stmt->fetch()) {
echo $profile_pic;
}
and this would be your android part.
byte[] decodedString = Base64.decode(strBase64, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
image.setImageBitmap(decodedByte);
Post a Comment for "How To Upload Long Blob (image) To Mysql Database Using Java And Retrieve In Php?"