1

How to send the Large encoded Image base64 string to server from android.

HI Friends,

 By default String value within 8000 characters is uploading to server.

 But Encoded Image base64 String length is more than 8000 characters.

More than 8000 characters is not uploading from android to mysql database.

please Give me a solution..!

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Check which request we're responding to
    if (requestCode == RESULT_LOAD_IMAGE) {
        // Make sure the request was successful
       // Log.d("Vicky","I'm out.");

        display(requestCode,resultCode,data);

    }
}

public void display(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK && data != null && data.getData() != null) {
        Uri selectedImageUri = data.getData();
        Bitmap selectedImageBitmap = null;
        try {
            selectedImageBitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), selectedImageUri);
        } catch (IOException e) {
            e.printStackTrace();
        }
        selectedImage.setImageBitmap(selectedImageBitmap);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        selectedImageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
        byte[] byteArrayImage = byteArrayOutputStream.toByteArray();
        encodedImage = Base64.encodeToString(byteArrayImage, Base64.DEFAULT);}}
an_droid_dev
  • 1,136
  • 14
  • 18
Lokesh GP Loki
  • 101
  • 2
  • 15
  • seem be a problem server side (mysql) and not client side – an_droid_dev Aug 10 '17 at 10:46
  • I agree with an_droid_dev – Himeshgiri gosvami Aug 10 '17 at 11:03
  • I tried Datatype MediumText,LongText and Longblob but ,It storing minimum 8000 characters but i need to store more than 8000 characters to server. – Lokesh GP Loki Aug 10 '17 at 11:09
  • what is the http-request type you are sending ? GET or POST? i doubt this is a web-server issue, not DB as mentioned data types supports way larger than 8K characters. what version of Mysql you are using, and what web-server? – Yazan Aug 10 '17 at 11:18
  • Webserver: apache 2.4.17 MYSQL VERSION : 10.1.9mariadb Used GET METHOD to send through android and in php we using same GET METHOD to recieving. – Lokesh GP Loki Aug 10 '17 at 11:27
  • switch to post, it will work, use TEXT or MEDIUM_TEXT on mysql – Yazan Aug 10 '17 at 11:34
  • I tried for POST method also and I used VARCHAR,MEDIUM_TEXT,LONGTEXT,LONGblob but it storing within the 8000 characters, would you please send me the some other solutions..! – Lokesh GP Loki Aug 10 '17 at 11:41
  • @LokeshGPLoki are you tried my solution? VARCHAR(65000) – an_droid_dev Aug 10 '17 at 11:48
  • can you (on server code) log or write to a file, the length of data received? before inserting in DB, ex, write in a file `$_POST['image_data'];` it's just a temporary thing just to see data size received by server. and if you have access to apache config, see this answer and check limits on your server https://stackoverflow.com/a/9691395/3604083 BTW it could be PHP config issue too, the answer shows all possible limits to check – Yazan Aug 10 '17 at 12:03

3 Answers3

1

just check your database structure image field have datatype longblob like below

like this

Omkar
  • 3,040
  • 1
  • 22
  • 42
  • I tried by using longblob,longText,mediumtext, but it not storing more than 8000 characters but it only storing within the 8000 characters. please give me some other solutions..! – Lokesh GP Loki Aug 10 '17 at 11:07
1

Store the image in a file and save the path of image in your database.

Trupti Nasit
  • 177
  • 2
  • 15
0

Change your data type to VARCHAR. Max lenght of it it's around 65000. You can find more info here

ALTER TABLE tablename MODIFY columnname VARCHAR(65000);
an_droid_dev
  • 1,136
  • 14
  • 18