0

Actually I'm getting upload files from my Android App and also download it. But seems that only the files uploaded can be downloaded for security reasons. My goal is to share (edit) some specific files created in the Google cloud with my Android App but I do not know how to do it. Actually, if I try to get some file created in the cloud, the downloadurl field is always set to null. Of course I'm usisng the same account for Google Drive user session and the signed Android app in Google API. I tried to change the file permissions on Google Drive cloud but without success. Some suggestion, please...

try {

                HttpClient client = new DefaultHttpClient();
                HttpGet get = new HttpGet(gFile.getDownloadUrl());
                get.setHeader("Authorization", "Bearer " + token);
                HttpResponse response = client.execute(get);

                InputStream inputStream = response.getEntity().getContent();
                jFolder.mkdirs();
                java.io.File jFile = new java.io.File(jFolder.getAbsolutePath() + "/" + gFile.getOriginalFilename()); // getGFileName() is my own method... it just grabs originalFilename if it exists or title if it doesn't.
                FileOutputStream fileStream = new FileOutputStream(jFile);
                byte buffer[] = new byte[1024];
                int length;
                while ((length=inputStream.read(buffer))>0) {
                    fileStream.write(buffer, 0, length);
                }
                fileStream.close();
                inputStream.close();
                return jFile;
            } catch (IOException e) {        
                // Handle IOExceptions here...
                return null;
            }
5
  • How download from my Android App a file created in Google cloud? The only files that I get to download are the created and previously upload from my Android app. Sep 27, 2012 at 20:30
  • Code please? Do you mean Google drive too?
    – TheBlueCat
    Sep 27, 2012 at 20:52
  • This is the code for download a specific file from Google Drive (cloud): Sep 27, 2012 at 21:00
  • This code is working fine, but only with files previosuly upload from my app. see in this post full version (stackoverflow.com/questions/12520302/…). The issue is that other files in the cloud (google drive) can't be downloaded because .getDownloadUrl() and .getOriginalFilename() are null. So I think some problems or a missing something with permissions... Sep 27, 2012 at 21:10
  • I found this post: (stackoverflow.com/questions/12092056/…) So, would be required a drive.permissions.update in order to change the role field, and just in those files where .getDownloadUrl() and .getOriginalFilename() are null ??? in that case which role or field? Sep 27, 2012 at 21:51

1 Answer 1

0

DownloadUrl is only populated for non-Google docs files. If the files you are looking to download are Google Docs, you'll need to use one of the exportLinks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.