Search code examples
androidandroid-bitmapgoogle-drive-android-apidrive

Upload photo to drive without compression


I want to upload a photo from my camera directly into a drive folder:

OutputStream outputStream = result.getDriveContents().getOutputStream();
                    ByteArrayOutputStream bitmapStream = new ByteArrayOutputStream();
/* image is my Bitmap */
                    image.compress(Bitmap.CompressFormat.PNG, 100, bitmapStream);

                    try {
                        outputStream.write(bitmapStream.toByteArray());
                    } catch (IOException e1) {
                        Log.i(TAG, "Unable to write file contents.");
                    }

So im doing this and it's working. The problem is that my pictures in drive is in very low quality and i need to have a High Quality video.

I already tried this solution Converting bitmap to byteArray android

But then in Drive the photo wasnt recognize as media file and can't read it. I may have failed something.

EDIT: i've done exactly the same things that is there https://stackoverflow.com/a/13000774/6644403 and doing this way to get my Bitmap in ActivityResult :

try {
                    mBitmapToSave = MediaStore.Images.Media.getBitmap(this.getContentResolver(), data.getData());
                } catch (IOException e) {
                    e.printStackTrace();
                }

Solution

  • For Get Actual Image predefined path of Captured Image using

    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
    this.startActivityForResult(cameraIntent, 101);  
    

    After Captured Image you can get Captured Image on path which is set in cameraIntent. If you don't Want to set predefined path then check Intent data.

        if (resultCode == android.app.Activity.RESULT_OK && requestCode == 101) {
            try {        
                path_mm = "Onsuccess_resultcode";
                generateNoteOnSD("photo34.txt", path_mm);
                Bitmap photo = null;
                if (data == null) {
                            //get Bitmap  here.
                } else {
                   Uri u1 = data.getData();
                   //get uri and find actual path on that uri.
                   }
               }catch(Exception ex) {}
    }
    

    Refer this link Upload large files to Google Drive using GD API for google drive Uploadation.