Google 文档视图 - URL 编码?
我正在尝试使用 Google 文档查看器。看来做PPT还不错。示例:
在我的应用程序中,我有文件为了安全起见,以私有方式上传。这似乎破坏了 Google 文档,或者可能是我编码错误。
我发送到 Google 文档查看器的 URL 如下所示(示例 URL):
这会破坏谷歌文档,它可以接受它。我需要对此进行不同的编码吗?
谢谢!
I'm trying to use the Google Docs Viewer. It seems to work fine for PPT. Example this works:
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):
That breaks google docs, it can take it. Do I need to encode this differently?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您至少需要将&符号(
&
)编码为%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 useencodeURIComponent()
你不能。您的文档必须可供公开访问,以便 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(您的问题历史记录建议),您将需要使用
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
如果您可以从 s3 php 库生成的即时 url 下载文件,您就可以做到这一点。您所要做的就是将 google url + 编码(即时生成的文件)。
如果链接未过期,Google 视图将能够读取它。
就是这样
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