Reputation: 500
I've been playing with Drive's ability to host HTML pages in a public folder. As per this page, you can get the URL to a file in the public folder using the folderID and the file name. Fantastic. The problem is that, if the file name changes, so too does the URL. This means external references to that file are now broken.
I investigated GDrives but I don't think it's going to work for me. My application is not a web site in the traditional sense. I'm just using public folders as a mechanism by which I can store HTML files, so that I can easily access all of them later by their individual URLs without having to sign in to Google Drive. Taken together, these HTML files do not form a web site, but rather are separate entities that happen to reside within the same folder in order to make management easier. It's important that the user not have to sign in to Drive again later when it's time to show the HTML page, as it's being rendered on kiosk computers.
Is there some other URL that can be used, perhaps one that uses the file ID instead of the file name? Or is there some other creative way to get around this problem?
Thx.
Upvotes: 0
Views: 7583
Reputation: 662
Checking the API documentation it seems is not possible to get a universal URL to access an HTML file as intended (displaying that HTML file on a kiosk), but with a little bit of Google AppsScript and knowing how URL are structured for files inside a Google Drive Hosted site, the following steps could solve problem.
I've created a Google AppsScript web app using the Serving content capability, which dynamically recreate the URL to the published HTML file. Because the Google AppsScript is running as myself, so there is no need for the end user to authenticate or approve the application, I only needed to Approve the app once from my account.
The live Proof of concept is here: https://googledrive.com/host/0B0CnV_gvF2TgNzBlbHBxeUlUYmM/base.html
The "before JS modifications" base.html page with the JS calls can be found here: https://drive.google.com/folderview?id=0B0CnV_gvF2TgNzBlbHBxeUlUYmM&usp=sharing
The public folder where the "iframed" HTML page is stored, can be found here: https://drive.google.com/folderview?id=0ByI2-lJS5-g4YXNtNzJkdWduQ1E&usp=sharing
I've used 2 different accounts to test that everything was working as expected even with files from different folders and accounts.
The AppScript code can be found here: https://script.google.com/d/1c9oJKLvNHrxkmEltTvm9OfZuirFJeJJojAORZ8mnlGKmm2UXy8yROM8Z/edit?usp=sharing
In short the steps:
- base.html
is a wrapper to call the AppScript and handle the result with a callback function (showIframe)
- the AppsScript receive folderId and fileId and create the current URL for the requested HTML file, then call showIframe function (specified in the prefix parameter when calling the AppsScript service)
- the showIframe
replace the src of an already present Iframe
I've used AppsScript, but the same thing can be done with a call to any page able to run some code server side and retrieve the current file name from the ID.
Keep in mind that the published folder ID, can't always be retrieved as one of the parents of the public file, because the file can be organized into a different directory from the user I'm accessing it. In the example above, the "iframed" file is not listed in the Google Drive structure of the user used by AppsScript.
Upvotes: 1