I'm trying to use the Google Docs Viewer. It seems to work fine for PPT. Example this works:
http://docs.google.com/viewer?url=http://www.microsoft.com/presspass/download/press/2008/02-01yahoo.ppt
In my app I have files uploaded as private for security. This appears to be breaking Google Docs or maybe I'm encoding something wrong.
The URL I'm sending to Google Docs Viewer is like so (sample URL):
https://s3.amazonaws.com/dev/1/attachments/243/1/original/02-01yahoo.ppt?AWSAccessKeyId=17VVCSSS3H6Y3129H3G2&Expires=1294131584&Signature=3141havYNS7JCpsTLE6Ppo3yXkc%3D
That breaks google docs, it can take it. Do I need to encode this differently?
Thanks!
You need to encode at least the ampersands (&) to %26
In whatever language you are using there should be a function for url encoding. In php it is urlencode(). In javascript you will want to use encodeURIComponent()
You can't. Your documents must be publicly accessible for Google's servers to view them and render them. When I try to view the URL you posted, it gives me "Access Denied."
Imagine trying to view a powerpoint on your computer at /Users/you/Desktop/mypowerpoint.ppt. Since it's not a publicly accessible file, you wouldn't expect anyone to be able to view it, let alone Google's servers. Google would not be able to access http://docs.google.com/viewer?url=file:///Users/you/Desktop/mypowerpoint.ppt, just like it can't get to your Access-Restricted page.
If, however, the URL you provide has an access key (which I see is a part of your "sample url") which allows anyone with that access key to view it, it should work, and #Mike is right -- you will need to URL encode it so as to not confuse Amazon's URL parameters with the Google Docs Viewer's parameters. In that case, if you're working with Ruby on Rails, which your history of questions suggestions, you'll want to use
<%=u "http://www.yoururl.com/?someparameter=true&file=myfile.ppt" %>
Well you can do this if you can download the files from the instant url generated by s3 php library. All you have tp do is to put google url + encoded ( instant generated file ).
Google view will be able to read it if the link is not expired.
that's it
$generated_file = $obj->gs_prepareS3URL($file);
$encoded_url = rawurlencode($generated_file);
$google_docs = "http://docs.google.com/viewer?url=";
redirect($google_docs.$encoded_url);
Related
I have upload json file to my google drive, for using as source data for QlikSense (via REST API) with permission = anyone, with the link can view.
So is it possible to generate link from that file?
Thank you for your help
Regards
Direct Download URL of regular file:
https://drive.google.com/uc?export=download&id=YOUR_ID
But I prefer another way, to copy the JSON data to a new Google Document (not regular file), then make it available to anyone with the link, and make your GET requests to a link like:
https://drive.google.com/file/d/YOUR_ID/export?format=txt
You may want to check the Files: get
Gets a file's metadata or content by ID.
Using the API Explorer, you can use this to see the actual API request and response
Then you will get a response:
If you will not be using the API you can get the link by right click -> Get shareable link.
Hope this helps.
Few days ago I was able to make request to:
https://drive.google.com/a/{{domain}}/file/d/{{docDriveId}}/image?pagenumber=1&w=400
Via this API I was able to get image preview on multi-page documents.
Seems it's there, but times-out after some time. It doesn't work anymore. Does anyone know what happened? It seems there's no documentation on this API.
On the other hand, I am aware of the thumbnailLink URL when getting document object via API, but this will only get 1st page preview.
Any alternative solutions to this?
Thanks a lot,
M
That URL is not a part of the official Drive API and is not guaranteed to remain stable. The Drive API doesn't include the ability to fetch per-page image previews of documents, but you may want to investigate using the embedLink as an alternative: https://developers.google.com/drive/v2/reference/files
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/.
I'm trying to download content from a Google docs file using Javascript using the Drive SDK.
I retrieve the metadata, and parse the exportLinks to get a URL
https://docs.google.com/feeds/download/documents/export/Export?id=xxx&exportFormat=html
My code is similar to Google Drive using JavaScript: Handling file content except I'm using exportLinks:text/html instead of downloadUrl.
If I try to retrieve that URL, I get "405 OPTIONS method not allowed".
(as an aside, if I download a non-docs file using the downloadUrl, all is OK).
So I'm guessing that either:-
a) I shouldn't be using Drive to retrieve Docs files
b) I should be using the exportLinks is some other fashion, or
c) I need to implement the same iframe workaround that is used for upload here Does https://www.googleapis.com/upload/drive/v2/files really support CORS?
Export links do not currently support CORS. It is something we are working on, so sorry about that.
If you can use the iframe hack for now, until we get it working, then please do.
I can't find the answer to this in the API docs or elsewhere. I see in the docs says you can get a downloadURL of a file, but it refers to it as a 'short lived URL'. What does that mean?
I need to upload images and get a permanent URL of that image that is the direct URL than can be embedded into emails or web docs etc. Is that possible?
Thanks
Yes, you can get a permalink to any file hosted on Google Drive in a public folder. Just note the folderID:
and paste it to the following URL:
http://googledrive.com/host/<folderID>/<filename>
or you can create a short custom alias using G Drives: http://gdriv.es/<alias>/<filename>
https://developers.google.com/drive/v2/reference/files#webContentLink
downloadUrl is short lived, but webContentLink is a permanent link. It's odd that one is a URL and the other is a "link", but I guess it probably has to do with the additional query params in the strong. Maybe that makes it not just a URL? :)
That property is only available for files that are publically readable, so you may have to use the SDK/API to set the permissions first.
In case someone encounter the same problem and don't want to do with deprecated Google Drive solution above and requires frequently changed files with exact same url, you can use Dropbox. Steps:
Download the program and share a folder (tutorial)
Copy a file into that folder; wait for sync with Dropbox
Go to your dropbox.com account
Share your file by button, get something like:
https://www.dropbox.com/s/d28d8scvr3rfy48/foo.exe?dl=0
Rename it to:
https://dl.dropboxusercontent.com/s/d28d8scvr3rfy48/foo.exe?dl=0
Now you have a public, unchanged url for all your foo.exe changes.
Enjoy, don't waste time with sites offering you file hosting and they change the URL for same files.
If you share a file publicly in GDrive, you can use the following link to make the file download directly:
https://drive.google.com/uc?export=download&id=FILEID
The problem happens when you want to change the file (for version controlled download, in instance) and keep the same downloading link.
You can use a URL Shortener like bitly.com and use a Branded Bitlink to change the destination URL keeping the input URL.
I hope it works, good luck!
It seems if you have file ID you can access it with such url:
https://drive.google.com/open?id=file-id-here
If file is public, you'll see it immediately but if not, you're be asked to login
I don't know how often this changes but I was looking for a dynamic solution where I wouldn't need to manually upload to another site and the provided solutions weren't working.
Here's the url that worked for me:
https://lh3.google.com/u/0/d/<file_id>
Where file_id is the getId() using the google apps script drive API. Secondly the file must be shared publicly like posted previously
Secondly I imagine the lh3 are different cdn's though I cannot confirm since lh1/2 don't work and everything higher than 3 redirects to lh3
I don't know if such API for google drive exists, but I think you should also have a look at dropbox,
which will meet all the demands that you mention in your question.
Also there are some very cool applications developed just for dropbox, like pancake.io which lets you share links of text, html files, in an html page format.
that + permanent link is always there.
You can use gdriveurl.com, it got updated and now allows users to log in with their google drive account and share the list of files instantly, getting for each file "View" & "Download" short permalink.
There's also the old solution (login to Google Drive, set everything to "Public on web", copy share link, convert it into the gdriveurl.com textarea in the homepage), but it's just a waste of time, you should try "MyDrive" api.
Not sure if the link generated here is guaranteed to be permanent, but Google Drive Direct Link Generator does the job of generating a direct download link.
Just make sure your file's sharing setting is set to Anyone with the link