Upload feature from Google drive & local - java

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.

Related

Saving a file in Google Drive from Android

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

How to create a Spread Sheet on Google Drive Using Java and Drive API

I'm trying to create a spreadsheet on google drive using DRIVE API in Java, the documentation on google site is very confusing, can somebody please help me by pointing to a sample example that demonstrate the creation of documents on google drive in Java using the latest DRIVE API?
Based from this SO question, using Drive API seems to only let you create new empty files with the spreadsheet MIME type. The Drive API is only concerned with operations at the whole file level. It is only possible in Google Drive to upload the created spreadsheet.
You can use Google Sheets API (formerly called the Google Spreadsheets API) which lets you develop client applications that create, read and modify worksheets and data in Google Sheets. This API can manage the worksheets in a Google Sheets file. You should strongly consider using a GData client library to interact with the API. Follow the following steps here to setup a development environment for working with the Sheets API.
You can create a spreadsheet via Drive API by calling files.create() with mimeType=application/vnd.google-apps.spreadsheet and uploading a CSV file. See Importing to Google Docs Types where there's a Java sample.

Uploading ZIP via Google App Engine servlet, and saving content to Cloud Storage (Java)

I'm searching for the best approach to do the following:
User uploads a large (~500 Megabytes) ZIP file via an App-Engine servlet
All the extracted content should be saved to a Cloud Storage bucket
A DB record should be inserted to a table on CloudSQL with the URL of every stored file.
What will be the best approach to implement such a behavior?
Thanks!
You can easily upload the 500 MB .ZIP directly to GCS, but then you can't unpack it there -- and it's too large to get it into app engine for unpacking. Rather, for this latter task, I would use google compute engine, which is not subject to the same limitations as google app engine.

how to upload an excel sheet in google drive using java api

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

Google App Engine is not picking up Log4j

Google App Engine does not create a file when using the file appender.
Google App Engine simply does not provide access to the file system. You can read from within your web-application, but you can't write anywhere. Those restrictions are the same for any framework you are using.
Most common example: you can upload file only with File Streaming API, without storing actual file in some temporary folder.

Categories

Resources