AWS PHP SDK Version 2 S3 filename encoding issue

[亡魂溺海] 提交于 2019-12-11 09:15:58

问题


We've been using the AWS SDK with pretty good results for uploading/grabbing files, but we ran into a snag.

There is a file stored in S3 that looks like it was urlescaped. "/mefile/412501_413000/412604_-12%20C008%20Fil%20R[1].doc.gpg"

So far the SDK has managed to handle every mangled filename we've thrown at it. But when I try a "doesObjectExist" I also get a failure for that file.

$s3->doesObjectExist("mabucket","/mefile/412501_413000/412604_-12%20C008%20Fil%20R[1].doc.gpg")

will always fail. I've tried uploading that file from a local storage and that fails as well. I get a funky exceptions: "The request signature we calculated does not match the signature you provided. Check your key and signing method."

Is there any trick I need to encode the filename with before using the "doesObjectExist". It seems to handle all sorts of bad filenames already (spaces/utf-8 chars/& etc), so I'm confused why this doesn't work.

UPDATE: Upgrading to the latest AWS SDK for PHP 2.2.1. Was running on version 2.1.0 which apparently had several bugs. If you are on Ubuntu 10.04, this is a bit rough. (See comments about PHP version upgrades here: http://www.zalexblog.com/2011/01/07/installing-php-5-3-3-on-ubuntu-10-04/)


回答1:


Can you try with html_entity_decode ?

$s3->doesObjectExist("mabucket",html_entity_decode("/mefile/412501_413000/412604_-12%20C008%20Fil%20R[1].doc.gpg"))



回答2:


Upgrading to the latest AWS SDK for PHP 2.2.1. Was running on version 2.1.0 which apparently had several bugs. If you are on Ubuntu 10.04, this is a bit rough. (See comments about PHP version upgrades here: http://www.zalexblog.com/2011/01/07/installing-php-5-3-3-on-ubuntu-10-04/)




回答3:


urldecode() of the key/filename worked for me



来源:https://stackoverflow.com/questions/15558289/aws-php-sdk-version-2-s3-filename-encoding-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!