Convert html to google docs or docx using drive api v3 - html

I'm trying to convert a html file (or preformatted html String) to Google Docs using drive api v3 and android studio, using these lines:
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle("report.html")
.setMimeType("text/html")
.build();
(I extract the code from android-demos-master examples )
If I try put another mimetype like "application/vnd.google-apps.document", my app crash. I want to upload the file and convert to Gdocs editor or Docx. I need convert before or after upload the file. Can someone guide me?

Using the python libraries, I found I had to specify two mimetypes:
Use 'application/vnd.google-apps.document' when creating the metadata for the Drive file. This is the type of file you want created - a Google Document.
Use 'text/html' for the object representing uploaded data, as that is the type of the content. In python, this were objects of type io.MediaUpload (file upload) or io.MediaIoBaseUpload (in-memory content).
I imagine it's something similar in Java.

Related

Is there is any changes in mimeType, exportLinks or downloadURL for the documents that are created or edited in GoogleDocs

In my applciation, i used to convert the googleDocs edited documents to .pdf format. But, recently i am facing issue in converting it. Is there is any changes happended in API level ? i am using google-api-services-drive.jar -version v2-rev1-1.7.2-beta.

Can I upload a zip file with htmls or a zip file with json files using the Web Interface of Watson Retrieve and Rank service?

Can I upload a zip file with htmls or a zip file with json files using the Web Interface of Watson Retrieve and Rank service ?
No, the web interface doesn't support that. It will let you upload multiple doc/PDF files in parallel though, without needing to zip them (up to 50 at a time)
But if you've already got your content in the right JSON format, you can post it directly to the R&R collection (e.g. Using curl or your scripting language of choice) without the web interface anyway.
The content will show up in the web UI when you come back.

How to generate API docs from .json descriptor file?

I have generated a node.js application skeleton using Restlet studio. This skeleton contains a swagger2.json definition file, which contains roughly all API information that I'd like to have. Is there any straightforward way to display those information as docs, in a more readable format? I have researched and found stuff like swagger.io, not quite sure how to use it though, even after looking through the documentation.
Edit: I copied all files from dist folder into my root application folder, then modified index.html:
var url = window.location.search.match(/url=([^&]+)/);
if (url && url.length > 1) {
url = decodeURIComponent(url[1]);
} else {
url = "json/swagger2.json"; //I replaced here with my json
}
however, when I launch it in my browser, all I get is:
Please specify the protocol for file:///home/osboxes/Desktop/nodejsServerSkeleton_3/index.html/json/swagger2.json
In other words, can I do it for a local swagger.json file? Or only for publicly accessible resources?

Need to convert html to google doc native format using Java

I've read through the API documentation at https://developers.google.com/drive/v2/reference/ however I cannot find the answer to my question. And attempts to google a solution have failed.
I have a series of previously uploaded small HTML files sitting in Google Drive. What I want to do is write a short application to convert each of these to native Google Document format (mime type "application/vnd.google-apps.document").
I want to do this using Java code and not using GAS code.
The approach I used was to query drive for the File object corresponding to the item I want to convert. Then I pull that file's content as a string. Then I create a new file of mime type "application/vnd.google-apps.document" and upload it with the HTML content. Not surprisingly it didn't work.
So then I tried a different approach: Upload the content as "text/html" but set the "convert" flag to "true". Well I didn't see any direct API to set the convert flag to true. So I tried:
File oBody = new File() ;
oBody.setTitle ( sTitle ) ;
oBody.setDescription ( sDescription ) ;
oBody.setMimeType ( sMimeType ) ;
oBody.set("convert", bConvert);
This did not fail. But it did not create a Google Document either. It just created a text file identical to the original file.
How do I upload a document containing "text/html" content and get Google Drive to convert it automatically to a Google Document?
The convert flag has to be set in the files.insert request and not the File resource.
Using the snippet in the files.insert documentation as reference, this is what you should do:
...
File file = service.files().insert(body, mediaContent).setConvert(true).execute();
...

Copy document contents in google drive api

I need to copy the content of a document into another, both stored in google drive, using Google Drive Api for Java. I'm able to upload or download documents but I don't know how directly transfer the content of a document into another one. I thought of something like that:
public void copyContent(String sourceId, String destinationId) {
File sourceFile = service.files().get(sourceId).execute();
AbstractInputStreamContent content = null; //sourceFile.getContent()??? :-(
File destinationFile = service.files().get(destinationId).execute();
service.files().update(destinationId, destinationFile, content).execute();
}
There's a way to get the file content as AbstractInputStreamContent? Or maybe it exists another approach to copy contents? I need a solution without exporting / uploading documents because I noticed some conversion problem. Thanks!
You can use the files.copy method of the Drive API to create a copy of an existing document:
https://developers.google.com/drive/v2/reference/files/copy