开发者

Google Docs View - URL Encoding?

开发者 https://www.devze.com 2023-02-10 01:39 出处:网络
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

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号