I'm trying to download an object from AWS S3 using the SDK for PHP.
$filename = "filename with spaces in it.jpg";
$src = "path/from/bucket-root/".$filename;
$result = S3Client->getObject([
'Bucket' => 'my-bucket-name',
'Key' => $src
]);
When I run this, I get an error:
Error executing "GetObject" ... GET filename%20with%20spaces%20in%20it.jpg resulted in a 404 Not Found response:
The S3 client is encoding the spaces but then not able to resolve the path.
Ive tried all of the following:
$filename = urlencode("filename with spaces in it.jpg");
$filename = urldecode("filename with spaces in it.jpg");
$filename = addslashes("filename with spaces in it.jpg");
$filename = str_replace(' ','+',"filename with spaces in it.jpg");
And several combinations - Im just throwing turds at the wall at this point.
My key path and bucket name/route are correct since I am able to successfully get object without spaces in the filename.
How do I grab this object with spaces in the filename?