Google 文档视图 - URL 编码?

发布于 2024-10-17 08:33:56 字数 838 浏览 1 评论 0原文

我正在尝试使用 Google 文档查看器。看来做PPT还不错。示例:

http://docs.google.com/viewer?url=http://www.microsoft.com/presspass/download/press/2008/02-01yahoo.ppt

在我的应用程序中,我有文件为了安全起见,以私有方式上传。这似乎破坏了 Google 文档,或者可能是我编码错误。

我发送到 Google 文档查看器的 URL 如下所示(示例 URL):

https://s3.amazonaws.com/dev/1/attachments/243/1/original/02-01yahoo.ppt? AWS访问密钥ID =17VVCSS3H6Y3129H3G2&Expires=1294131584&Signature=3141havYNS7JCpsTLE6Ppo3yXkc%3D

这会破坏谷歌文档,它可以接受它。我需要对此进行不同的编码吗?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淡写薰衣草的香 2024-10-24 08:33:56

您至少需要将&符号(&)编码为%26

无论您使用什么语言,都应该有一个用于url编码的函数。在 php 中,它是 urlencode()。在 javascript 中,您需要使用 encodeURIComponent()

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()

青巷忧颜 2024-10-24 08:33:56

你不能。您的文档必须可供公开访问,以便 Google 服务器查看并呈现它们。当我尝试查看您发布的 URL 时,它显示“访问被拒绝”。

想象一下尝试在计算机上查看 /Users/you/Desktop/mypowerpoint.ppt 上的 Powerpoint。由于它不是一个可公开访问的文件,因此您不会期望任何人都能够查看它,更不用说 Google 的服务器了。 Google 将无法访问 http:// /docs.google.com/viewer?url=file:///Users/you/Desktop/mypowerpoint.ppt,就像它无法访问您的访问受限页面一样。

但是,如果您提供的 URL 有一个访问密钥(我看到它是您的“示例 url”的一部分),它允许任何拥有该访问密钥的人查看它,那么它应该可以工作,并且 @Mike 是对的 - 您会需要对其进行 URL 编码,以免 Amazon 的 URL 参数与 Google 文档查看器的参数混淆。在这种情况下,如果您正在使用 Ruby on Rails(您的问题历史记录建议),您将需要使用

<%=u "http://www.yoururl.com/?someparameter=true&file=myfile.ppt" %>

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" %>
我一向站在原地 2024-10-24 08:33:56

如果您可以从 s3 php 库生成的即时 url 下载文件,您就可以做到这一点。您所要做的就是将 google url + 编码(即时生成的文件)。

如果链接未过期,Google 视图将能够读取它。

就是这样

$generated_file = $obj->gs_prepareS3URL($file); 
$encoded_url = rawurlencode($generated_file);
$google_docs = "http://docs.google.com/viewer?url=";
redirect($google_docs.$encoded_url);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文