googleworkspace / android-samples

Android samples for Google Workspace APIs
Apache License 2.0
636 stars 410 forks source link

Can not download some files #70

Closed Even201314 closed 6 years ago

Even201314 commented 6 years ago

I can download Image from google drive. But can not download Excel、Word or PDF. Here is the exception:

 com.google.android.gms.common.api.ApiException: 10: This file is not openable.

I don't know why the file is not openable.Because I use the same method to upload Excel and Images.

The Code:

        OpenFileCallback openCallback = new OpenFileCallback() {
            @Override public void onProgress(long bytesDownloaded, long bytesExpected) {
                int progress = (int) (bytesDownloaded * 100 / bytesExpected);
                Log.d(TAG, String.format("Loading progress: %d percent", progress));
            }

            @Override public void onContents(@NonNull DriveContents driveContents) {
                try {
                    InputStream inputStream = driveContents.getInputStream();
                    java.io.File file = new java.io.File(getContext().getCacheDir(),
                        metadata.getOriginalFilename());
                    OutputStream output = new FileOutputStream(file);
                    try {
                        byte[] buffer = new byte[4 * 1024]; // or other buffer size
                        int read;

                        while ((read = inputStream.read(buffer)) != -1) {
                            output.write(buffer, 0, read);
                        }

                        output.flush();
                    } finally {
                        output.close();
                        mDriveResourceClient.discardContents(driveContents);
                    }
                } catch (IOException e) {
                    onError(e);
                }
            }

            @Override public void onError(@NonNull Exception e) {
                // Handle error
                // [START_EXCLUDE]
                Log.e(TAG, "Unable to read contents", e);
                DialogUtil.hideLoadingDialog();
                // [END_EXCLUDE]
            }
        };

        mDriveResourceClient.openFile(driveFile, DriveFile.MODE_READ_ONLY, openCallback);
MikiVanousek commented 6 years ago

Hey, i got same issue. I wrote post on StackOverflow (https://stackoverflow.com/questions/47518464/google-drive-api-cant-open-all-file-formats), but nobody answered. I will propably write to google with this issue today. It would be nice to have coment, that you have replicated the issue.

kbboss commented 6 years ago

@MikulasVanousek yes I got the same problem that can't open the office formats and download it, then the code throw the same exception. How do you fix it?

kbboss commented 6 years ago

@Even201314 How do you fix it?

MikiVanousek commented 6 years ago

I dont' think it is possible to open office formats with google drive api

On Thu, Jun 28, 2018, 4:43 AM shawsen notifications@github.com wrote:

@Even201314 https://github.com/Even201314 How do you fix it?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/gsuitedevs/android-samples/issues/70#issuecomment-400893192, or mute the thread https://github.com/notifications/unsubscribe-auth/Af2tUrd1RD_TwBGkeoIj4rNo6qri4yXRks5uBELOgaJpZM4RkN4W .

kbboss commented 6 years ago

@MikulasVanousek Thanks MikulasVanousek .

This google drive api team was so lazy that nobody from team can focuse on it.

I have some question about thumnail.

How do you get the image‘s thumnail by api?

erickoledadevrel commented 6 years ago

This issue tracker is for reporting bugs in the sample code. For general support options please see this page:

https://developers.google.com/drive/android/support