简体   繁体   中英

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

I wasnt asking for rights to WRITE_EXTERNAL_STORAGE, it was in my manifest but since api23 i need to explicit and ask if the user ok.

Now it's good.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM