Lokesh GP Loki
Lokesh GP Loki

Reputation: 101

How to send Large Encoded base64 Image String from Android to Mysql

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);}}

Upvotes: 1

Views: 1136

Answers (3)

Trupti Nasit
Trupti Nasit

Reputation: 177

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

Upvotes: 1

an_droid_dev
an_droid_dev

Reputation: 1136

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);

Upvotes: 0

Omkar
Omkar

Reputation: 3100

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

like this

Upvotes: 1

Related Questions