Good morning, I am trying to write a simple Android app that just stores a file in Google Drive so that I can retrieve it from other locations. I followed the examples on the Google tutorial, and I'm using exactly their code, but the result produces no error and my file doesn't get stored.
Since I'm using exactly the example code, can anyone suggest what my next step might be to try to get this working?
Edit with more information:
I'm using the google quickstart example here:
https://developers.google.com/drive/api/v3/quickstart/java
and tried to combine this drivesample in order to upload a file:
https://github.com/google/google-api-java-client-samples/blob/master/drive-cmdline-sample/src/main/java/com/google/api/services/samples/drive/cmdline/DriveSample.java
I was expecting to see the result when I go to my google drive page on my computer.
Edit Again: Perhaps my attempt to work the two of these together is what I'm doing wrong. I will also accept as an answer any link to a good step by step tutorial to simply uploading some bytes to Google Drive that will show up as a file!
If you are looking for a reference on how to upload files using Drive API in Java, you can refer in this official document Upload file data.
Simple upload - upload the media only, without any metadata.
Multipart upload - upload both the media and its metadata, in a single request
Sample Java Code (Multipart Upload):
File fileMetadata = new File();
fileMetadata.setName("photo.jpg");
java.io.File filePath = new java.io.File("files/photo.jpg");
FileContent mediaContent = new FileContent("image/jpeg", filePath);
File file = driveService.files().create(fileMetadata, mediaContent)
.setFields("id")
.execute();
Note: Your FileContent() expects a file type in its first parameter, you can choose for a specific file type based on the MIME Types provided under the additional references
Additional References:
Class FileContent
Google Workspace and Drive MIME Types
Google Workspace documents and corresponding export MIME types
Google Drive API in Android Studio Tutorial (PART 1)
Google Drive API in Android Studio Tutorial (PART 2)
Upload PDF files to Google Drive using Google Drive SDK in Android Studio PART 3
Related
Is there a way to unzip a zip file that is available in google drive using google drive java api.
i Am able to retrieve all the files from a particular users drive , now what i need to do is, if a file is a zip file, i need to extract it and get the files available inside it.
Thanks in advance.
Need Java Code to convert Google Drive Spreadsheet to Excel. Later I want to send the converted file as mail attachment.
I am using this code to retrieve the file metadata -
services.files().get(fileObj.getId()).executeAsInputStream();
I have a code to send the mail, but the problem is if I use the above code, the attachment is like a link to Google Drive document.
The File object has exportLinks property that
"Links for exporting Google Docs to specific formats."
exportLinks.(key) can be used to get the link for a specific format. Replace the key with the mimeType you want the file exported to (if I remember correctly)
You can find more info about the exportLinks keys (and Document Downloading in general) here
Is there a way to upload a file from Google Drive to Blobstore using a Google Appengine Form.
In have a user form which require attachment feature . The attachment can be a file from local or from google Drive .
It Would be nice if any Google Developer post a Java reference code
You can use the Google Docs Picker to select a file on disk or on Google Drive : https://developers.google.com/picker/docs/?hl=fr
For Google Drive files, you can download its on App Engine and then store into the Blobstore or Google Cloud Storage : https://developers.google.com/drive/web/manage-downloads
It's just reading file input stream and write file output stream where you want (but not on file system because it's impossible on App Engine for security reasons)
Relative to Google, there is no good reasons to use blobstore anymore so I advise you to use Cloud Storage.
In the Google developers code, method to upload a spreadsheet is given for .net but not java . Does any one know the sample code for this . code on how to convert an excel file to a spreadsheet and upload it will also do .
Can you please check the below url. It might help you
http://stackoverflow.com/questions/19361814/create-spreadsheet-using-google-spreadsheet-api-in-google-drive-java
login/OAuth2 The Google "DrEdit" tutorial is a good starting place for login/OAuth2 etc.
Upload: The only method I have seen uses Google drive sdk
Java example here:
https://developers.google.com/drive/v2/reference/files/insert
An example of the convert, (in PHP) using the same API,
Create a Google Drive Spreadsheet from a local CSV file via the Google Drive API
Is it possible to download files of any type from Google Docs using the Google Docs API? (jpg, zip, txt)
I can figure out how to download word, powerpoint, and excel files but want to be able to upload and download any type of file to Google Docs. I know it is possible to do this with the online uploader but can't seem to get the downloading part to work with the API.
I'm using the Java wrapper to the API. Is it possible to use the Java version of the API to download all file types?
Since the last answer was written, that API is deprecated. There's sample Java code on the Google Dev page for the (newer) Google Drive API for managing downloads from Google Docs.
This handles a large variety of MIME types.
See this page http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html
and this for specifically downloading documents and files
http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#DownloadingDocsAndFiles
The document listing XML returned by google has file type and the URL to download the file in the node. You can use the URL to download the file contents.