AWS PHP SDK Version 2 S3 filename encoding issue

2019-08-09 00:50发布

问题:

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