Is it possible to covert Word docs to a Google Doc? - google-drive-api

I am uploading Word documents to Google Drive using the Google SDK. I can view these files once uploaded through the Google Drive interface, but to edit these documents I need to selected "Open with Google Docs". When I do this, Google makes another version of the file and saves it to my Google Drive.
I want to automatically create a URL for users to click on once their file has been uploaded, so I presume I somehow need to convert the uploaded file (Word Document) to a Google Docs file so a user can then edit it and save it. Is this possible?

You need to send the optional query parameter of convert
convert (boolean) Whether to convert this file to the corresponding
Google Docs format. (Default: false)
Documentation for Google Drive Insert

Related

How to link to a Google drive file? [duplicate]

Using the Google Drive API I can get a file's webViewLink to link to the file-preview in Drive, and the user can then select 'Open with Google Sheets' in the top bar to open the file up in Sheets.
Is there a way to skip that intermediary step, and link directly to that file in Google Sheets?
File.resource also contains a link called webViewLink
webViewLink string A link for opening the file in a relevant Google editor or viewer in a browser.
This will not work on all file types but it should work on sheets.
What are you seeing in webViewLink?
When I try, I get
"webViewLink": https://docs.google.com/spreadsheets/d/1egZQnArX7TOHlQWSHiba3TTNt9Y7JoqgDAIJMdM0MQ/edit?usp=drivesdk"
which directly opens the sheet.
So a couple of things:-
Are you sure that the file in question is a native Google spreadsheet, or is it, for example, an uploaded Excel
If your webViewLink is different, you could construct the URL yourself by setting your own file's ID after the /d/

Google Picker API hide native google drive workspace formats

In Google Drive a user can create a new Google Doc/Sheet/Slide/Form etc as a Drive native format. Is there a way to hide these types of files when using the Drive Picker API? I want the user to only see files they have uploaded (or have had shared with them) and not created in Drive.
For example, if I add a view to the picker with ViewId.DOCUMENTS, then everything from Google Doc, txt, and docx show up. Just haven't found away to filter out the Google Doc mime type.
Have you tried using setMimeTypes? Use it to specify what format do you want to be included.
Code:
var view = new google.picker.View(google.picker.ViewId.DOCS);
// include only txt and docx files
view.setMimeTypes("text/plain,application/vnd.openxmlformats-officedocument.wordprocessingml.document");
var picker = new google.picker.PickerBuilder()
.addView(view)
Output:
Note:
Drive picker was made for google drive. So it's natural to only have Views supporting its native file types.
What's good is that Google provided us a way of specifying file types not included in their views via setMimeTypes
Currently, I don't find any methods in excluding a certain mime type or view
Additionally, you can try setQuery. I tested this a bit and it seems view.setQuery("*.docx|*.txt") will result in all docx and txt files (in my case). You can combine this with or choose it over setMimeTypes. Just test it out to see what solution fits you.
Reference:
Picker

Google Docs document format?

What I'd like to accomplish: Download a Google Docs doc (with Google Drive API), modify it (for example highlight some text), then store it back to Google Drive (not messing up the format, so that it can be edited in the Google Docs app).
(Preemptive research: I know that you can do some integration with Google's hosted AppScript, but I want to do this offline. I also know that a Google Docs doc can be exported to other formats, but I see no sign of reimporting in the Google Drive API.)
I'm not hopeful this can be done:
* The meta-data file (that you can get via the Google Drive API) lacks a "downloadUrl" attribute
* In offline mode, the data (stored in .../File System/) is binary and the Unix "file " command doesn't know what format it is.
Is this off-limits with the current Google Drive API?
Your best (only) approach is to export the doc to a format that you can edit locally (html, docs, etc) and then reimport it. HTML is of course the easiest, but also the most lossy.

Make Save to Drive button convert a CSV to a Google Sheet

We are using the 'Save to Drive' button (https://developers.google.com/drive/savetodrive) on our web site to allow clients to save CSV exports to Google Drive.
Unfortunately, this saves the file to the drive but doesn't automatically convert it to a Google Sheet. This means that users have to click 'Open with Google Drive Viewer' and then 'File > Open with Google Sheets’ to convert the file to a spreadsheet in Google Drive. This makes for a poor experience for our users.
Is there a way to ask Google Drive to automatically convert these documents on import? Also, if there is a better place to ask this question let me know. Thanks!

How To Set MIME Type Of Google Drive File

Using the HTML (div to load plusone.js) approach, is it possible to set the MIME Type of the generated Google Drive file?
Background
I'm trying to download CSV documents into Google Drive. I want customers to be able to open these files in Google Sheets with just a single click. Google Drive does not associate .csv files with Google Sheets automatically which means customers have to click here and there before they get the documents to open (not so good for my business).
I tried serving the documents with Google Sheets custom MIME Type application/vnd.google-apps.spreadsheet but it seems Drive completely ignores it.
If manipulating MIME Types won't work, I'll like to know any other means of associating generated files with Google Sheets such that customers can open generated documents automatically with a single click.
NB: I know its possible to set MIME Types in the Javascript and server-side flows using the Drive API and I have experience with the Drive API so please lets skip that :) I just want to get this done in the HTML flow.
Thanks.
Turn on conversion during uploads with convert parameter.
POST https://www.googleapis.com/upload/drive/v2/files?uploadType=media&convert=true