2

I have image in ImageView that is selected by the user ... how can i insert it to mysql database table using php?

can anyone help me with that.

the type of column that i want image to save on it is Blob.

1
  • @jtheman imageView.buildDrawingCache(); bmIcone = imageView.getDrawingCache(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmIcone.compress(Bitmap.CompressFormat.PNG, 90, stream); byte [] byte_arr = stream.toByteArray(); String image_str = Base64.encodeBytes(byte_arr); namevaluepair.add(new BasicNameValuePair("image",image_str)); php code $base= $_REQUEST['image']; $buffer = base64_decode($base); Commented Feb 10, 2013 at 12:48

2 Answers 2

4

OK that i found a solution for my question

code in java assuming that the image is already converted to bitmap:

        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bmIcone.compress(Bitmap.CompressFormat.PNG, 90, stream);
        byte[] byte_arr = stream.toByteArray();
        String image_str = Base64.encodeBytes(byte_arr);
        namevaluepair.add(new BasicNameValuePair("image", image_str));

in server :

$base= $_REQUEST['image'];
    $buffer = base64_decode($base);

    $buffer = mysql_real_escape_string($buffer);

then inserting the $buffer to table blob column type

Sign up to request clarification or add additional context in comments.

Comments

0

First, you will have to call your php in android. Many answers already exist on this topic:

To answer your question, this tutorial teaches you how to write your php to store images in MySQL:

1 Comment

thx for your help but the tutorial u gave it to me is for html page. android is different i think.. what i am doing right now is converting the ImageView to a bitmap and then convert the bitmap to String by encoding it using base64 ,then send it to php and decode it ... the problem is how can i insert it into table after decoding it? ... or is there any different solution for inserting image to mysql tables?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.