ChromeOS App: Simple example app which opens/saves to Google Drive as well as Download and External Drive - google-chrome

I've succeeded in using the filesystem API in a Chrome App on my Chromebook. But none of the examples I've found allow you to open files from Google Drive. Any number of apps on the Chromebook (supplied or added) open the exact same dialog but with Google Drive showing on the left along with Download and External Drive.
Is there a simple example App which shows how this is done?
Or am I simply missing some concept which will make even the Diff or TextEdit examples work this way if done (like pushing the App to the store, perhaps -- right now I'm just loading and packing my own off local storage)?

From reading your comment it seems that you will want to use google drive sdk in order to integrate the 'open file' dialog into your web app.
and even more to the point - the file 'picker' - In order to integrate the file picker you will need to use google JS client lib. Then you will be able to open the file dialog with a code like this:
// Use the Google Loader script to load the google.picker script.
google.setOnLoadCallback(createPicker);
google.load('picker', '1');
// Create and render a Picker object for searching images.
function createPicker() {
var picker = new google.picker.PickerBuilder().
addView(google.picker.ViewId.IMAGE_SEARCH).
setCallback(pickerCallback).
build();
picker.setVisible(true);
}
Good luck.

The answer to this is to use the <input type="file" name="somename" size="chars"> code in the browser. That is what is producing this. It creates a standard way to read in the file from disk or Google drive. It's what I've seen in multiple apps. All the API stuff is a red herring, if what one wants is to get access to this simple dialog.
However, it doesn't allow me to WRITE, just to read, since one would expect it to be returning only the content of the file, not a file handle of any sort, or even the full name. I'll play with it and figure out whether there's any hook I can find to tell me to write it to Google drive (using the links Ido provided above). If anyone has suggestions on where to snag the full path (or an interesting Google Drive path) somewhere using this, I'll love to hear them.

Related

Unable to serve download links in google apps script

UPDATE: I have found a solution. This doesn't necessarily address every case, so I will leave the question open for a short time in case someone can enlighten me more. I solved it by changing the format of the url: Google Drive allows this format for downloading files:
https://docs.google.com/uc?export=download&id=FILE_ID
So I don't know if this is a problem for other URL's; nor actually exactly why the .getDownloadUrl() doesn't work ... maybe someone can explain. But for now this seems to work in the browsers that I can test ...
I have a simple WebApp script which I run on a Google Site by adding the Apps Script gadget. The gadget runs exactly as the Forms example on:
https://developers.google.com/apps-script/guides/html/communication#forms
The gadget is designed to do the following: when the page is loaded, a form is returned, and the user must enter a license key to get a link to download a product. My code serves the form OK, and gets the form submit OK; and it then validates the key, and if valid, sends back a link to download. All that works fine; and the problem is that no matter what I try to return for the download link, the caja iframe wrapper is preventing the click on the link from actually downloading the file.
My preferred URL to return is in fact via the Drive API: the download file is on the Google Drive, and I get the download link like so:
DriveApp.getFileById(downloadFileId).getDownloadUrl()
But when the returned link is clicked inside that caja iframe generated for the WebApp gadget, nothing happens. I have tried a few other URL formats pointing to that file on the Drive, but nothing is working for a download.
Is this possible?
.getDownloadUrl() method returns a temporary URL that can be used to download the file. This URL is valid only for a short period of time, after which it expires and does not return the file any more - that is probably why the links in your web app do not work. Can't remember exactly how long the URL is valid for, but I think it could be as short as 5 minutes.
Permanent download URL is stored in another file property: webContentLink. However, this property is not (yet) available through Google Apps Drive Service - you must use Advanced Drive Service to access it. You can enable Drive API under Advanced Google services in your script. After it is enabled, you can use it like so:
var file = Drive.Files.get(FILE_ID_HERE);
var dlUrl = file.webContentLink;
This will return the link just like the one you found and posted in your update. An advantage of using the Drive API to get the link, instead of hard-coding it, is that if Google ever changes the format of that URL, your code using Drive API to get the link will continue to work, while hard-coded links will not.
Full Drive Web API reference (what Advanced Drive Service uses) is at https://developers.google.com/drive/v2/reference/.

How to edit HTML in Google Drive?

I have hosted a HTML file created on my PC (along with a stylesheet) on Google Drive using the script described here.
I have given out the link and it seems to be working fine (no reported issues from those I've sent it to).
I have just discovered a minor omission from the file, I need to add another sentence. This should be ridiculously easy on a PC, I could just open it on notepad!
I can't find a way to edit it on Google Drive, the only connected apps are the viewer and Docs.
The viewer, as the name suggests, will only let me view the HTML, and the docs app won't let me save it back to the original file.
Obviously I could download it then upload again, but from experience it will probably give me a different URL.
Is there any way for me to do this while keeping the link the same, as I have already given the address out?
Currently you can't. You can only preview html files, that is preview the code or preview the rendered content, but you cannot natively edit the code. You have two options:
use a third party extension, such as Neutron Drive or Drive Notepad.
install the Google Drive Desktop App, edit your files locally and save. Changes will be uploaded automatically.
I have just used HTML Editey chrome app
You can do this through file revisions. Hopefully, Google adds another way, but using the revision feature works for me. To revise your file, click the check mark in the Google Drive file list, click more, and then click "Manage revisions...". In the box that pops up, click upload new revision and then you're set.
You may also be able to edit html files stored in google drive through other plugins, but I do not use any at this time to know of them.
Update!
go to drive right click your html file
choose "open with" then "connect more apps"
when app library pop up search for "notepad" then choose "drivenotepad"
after it connect to drive, select it, you will get code editor.

Replacement for fileEntry.toURL() in Chrome Packaged Apps

I'm using the HTML5 FileSystem API in a Chrome Packaged App to write to a log file. I want the user to be able to download this file, so I tried something along the lines of:
fs.root.getFile('log.txt', {create: false}, function(fileEntry) {
var url = fileEntry.toURL();
// do something with the file url
});
This doesn't help though, because the URL is something like filesystem:chrome-extension://eekedjcagggbfigdmifkmhkjbhiklnpj/temporary/log.txt and it's not possible to open it somewhere.
What technique would you recommend to make a FileSystem API file in a Packaged App downloadable?
Edit: After reading through Ben Well's answer below, I realized that I'll have to clarify even more what I want. It would seem especially nice to me if there would be a technique that doesn't imply loading the HTML5 Filesystem API file contents, building a blob from it and writing that to a user-chosen path with chrome.fileSystem API.
Have you tried using chrome.fileSystem.chooseEntry? This API lets your app save files to the user's hard disk, wherever they want, letting your program have a Save As kind of command. This is a bit different to a download link, but is also more in harmony with V2 apps being like native apps.
chrome.fileSystem pops up a dialog asking the user to choose a location for a file. If you use the options for saving files, this returns you a file entry that has permissions to write to the location chosen by the user. The user can also create new files when you use these options.

Determine if a certain File is process by a project that uses Google Drive API

Good day! I am currently developing a website using Google Drive API. However, I am wondering if is it possible to know if a certain file is created/uploaded/shared by the project using an App Id. I was thinking if it is belong to the attributes of a file. But, when i checked, it seems that, there's no such thing.
What I am trying to do, is to filter the files' shared by the other user to the owner of the account using my web site. Is it possible? Any suggestions on how to do it?
Thank you in advance.
File metadata doesn't contain this information unfortunatelly, therefore you can't know if some file was created by your app or not. But FYI Google store it somewhere, if you will try to upload somefile without providing its content type (* / *) and after that try to open this file through browser you will see the message:
No preview available
This item was created with YourAppName, a Google Drive app.
Download this file or use one of the apps you have installed to open it.

Google docs api file view and download

Has anyone had any luck with the downloading of files using the google docs api?
I've been struggling for weeks now to get this working with no success.
https://developers.google.com/google-apps/documents-list/#downloading_documents_and_files
I can get the list of files successfully and display within my web page. However what i want to do next is allow the user to click on a file link which will then open it up in a google docs viewer allowing them to then view and edit that file.
Please advice.
I'd recommend using the newer Google Drive API which is easier to use, supports multiple programming languages and has documentation for each method, including downloading files:
https://developers.google.com/drive/manage-downloads