Amazon s3 URL +被编码为%2? [英] Amazon s3 URL + being encoded to %2?

查看:165
本文介绍了Amazon s3 URL +被编码为%2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WP Engine的托管帐户中集成了Amazon s3.一切都很好,除了其中带有+字符的文件.

I've got Amazon s3 integrated with my hosting account at WP Engine. Everything works great except when it comes to files with + characters in them.

例如,在以下情况下,文件被命名为: test + 2.pdf http://support.mcsolutions.com/wp-content/uploads/2011/11/test+2.pdf =不起作用.

For example in the following case when a file is named: test+2.pdf http://support.mcsolutions.com/wp-content/uploads/2011/11/test+2.pdf = does not work.

以下URL是亚马逊URL.请注意,+字符已编码.有没有办法防止/改变这一点? http://mcsolutionswpe.s3.amazonaws .com/mcsupport/wp-content/uploads/2011/11/test%2b2.pdf

The following URL is the amazon URL. Notice the + charcter is encoded. Is there a way to prevent/change this? http://mcsolutionswpe.s3.amazonaws.com/mcsupport/wp-content/uploads/2011/11/test%2b2.pdf

其他URL可以正常工作: 亚马逊-> http://mcsolutionswpe.s3. amazonaws.com/mcsupport/wp-content/uploads/2011/11/test2.pdf 网站-> http://support.mcsolutions.com/wp- content/uploads/2011/11/test2.pdf

Other URLs work fine: Amazon -> http://mcsolutionswpe.s3.amazonaws.com/mcsupport/wp-content/uploads/2011/11/test2.pdf Website -> http://support.mcsolutions.com/wp-content/uploads/2011/11/test2.pdf

推荐答案

如果我正确理解了您的问题,那么不会,没有办法真正改变这个问题.

If I understand your question correctly, then no, there is no way to really change this.

原因似乎是很多年前在S3上做出的不幸的设计决定-当然,现在无法解决,因为它会破坏很多其他事情-这涉及到S3使用了错误的URL变体在URL的路径部分中转义(包括但不限于百分比编码").

The cause appears to be an unfortunate design decision made on S3 many years ago -- which, of course, cannot be fixed, now, because it would break too many other things -- which involves S3 using an incorrect variant of URL-escaping (which includes but is not quite limited to "percent-encoding") in the path part of the URL, where the object's key is sent.

在查询字符串中(在?之后但在片段之前(如果存在,以#开头的)URL的可选部分),+字符被认为等效于[SPACE](ASCII十进制) 32,十六进制0x20).

In the query string (the optional part of a URL after ? but before the fragment, if present, which begins with #), the + character is considered equivalent to [SPACE], (ASCII Dec 32, Hex 0x20).

...但是在URL路径中,情况并非如此.

...but in the path of a URL, this is not supposed to be the case.

...但是在S3的实现中.

...but in S3's implementation, it is.

所以+实际上并不表示+,它表示[SPACE] ...,因此,+也不能表示+ ...,这意味着需要使用不同的表达式传达+-值是%2B,即+的转义网址值(ASCII Dec 43,Hex 0x2B).

So + doesn't actually mean +, it means [SPACE]... and therefore, + can't also mean +... which means that a different expression is required to convey + -- and that value is %2B, the url-escaped value of + (ASCII Dec 43, Hex 0x2B).

当您上传文件时,+由您使用的代码转换(假设它理解了这个怪癖,显然确实如此),转换为S3期望的格式(%2B)...如此必须使用%2B进行请求,以便在下载文件时使用.

When you upload your files, the + is converted by the code you're using (assuming it understands this quirk, as apparently it does) into the format S3 expects (%2B)... and so it must be requested using %2B so when you download the files.

奇怪的是,但并不奇怪,如果您将文件存储在S3中,并且路径中有空格,则实际上可以使用+或空格甚至是%20来请求文件,而这三个文件实际上都应该获取文件...因此,如果您要查看路径中的+,则可以通过使用空格代替来解决此问题,尽管此解决方法应被描述为"hack"(如果有的话).解决方法做到了.该策略不适用于生成预签名GET URL的库,除非它们专门设计用于忽略S3的标准行为并执行您想要的操作,但是...对于公共链接,它基本上是等效的.

Strangely, but not surprisingly, if you store the file in S3 with a space in the path, you can actually request it with a + or a space or even %20 and all three of these should actually fetch the file... so if seeing the + in the path is what you want, you can sort of work around the issue by saving it with a space instead, though this workaround deserves to be described as a "hack" if ever a workaround did. This tactic will not work with libraries that generate pre-signed GET URLs, unless they specifically are designed to ignore the standard behavior of S3 and do what you want, instead... but for public links, it should be essentially equivalent.

这篇关于Amazon s3 URL +被编码为%2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆