php - Putting multiple objects in Amazon S3 with different meta data fails -
i've got array of file information being looped through , using aws php 2 skd upload contents of these files cloud, works brilliantly until try , add meta data, @ point, adds the metadata first object created, after following error message:
fatal error: uncaught aws\s3\exception\signaturedoesnotmatchexception: aws error code: signaturedoesnotmatch, status code: 403, aws request id: 8fc9360f2eb687ee, aws error type: client, aws error message: request signature calculated not match signature provided. check key , signing method., user-agent: aws-sdk-php2/2.2.1 guzzle/3.3.1 curl/7.24.0 php/5.3.13 thrown in d:\inetpub\wwwroot\thirdparty_resources\aws_sdk2\aws\aws-sdk-php\src\aws\common\exception\namespaceexceptionfactory.php on line 89
i've cropped code loop highlight area being naughty.
foreach($afiles $afile) { $arr_objectmeta = array( 'originalfilename' => $afile['filename'] , 'description' => $afile['filedesc'] , 'keywords' => $afile['filekeyw'] ); // file upload $obj_fileupload = $obj_s3->putobject($sbucket, $sbucketfolder . $sfilenametosave, $sfile, 'public-read', $arr_objectmeta); if($obj_fileupload) { $files_uploaded++; } else { $files_not_uploaded++; } // clear file upload s3 response object unset($obj_fileupload); // delete downloaded file unlink($sserveruploadfolder.$sfilenametosave); } so second time around loop, seems bomb because of different meta values. when meta data same, loop executes without issue. help/pointers great.
you might confusing putobject method method upload helper method.
the upload helper method available of version 2.4 of sdk. using upload method following:
try { $skey = $sbucketfolder . $sfilenametosave; $obj_fileupload = $obj_s3->upload($sbucket, $skey, $sfile, 'public-read', array( 'metadata' => $arr_objectmeta )); $files_uploaded++; } catch (\aws\s3\exception\s3exception $e) { $files_not_uploaded++; } you can same thing putobject method well, more verbose.
try { $obj_fileupload = $obj_s3->putobject(array( 'bucket' => $sbucket 'key' => $sbucketfolder . $sfilenametosave, 'sourcefile' => $sfile, 'acl' => 'public-read' 'metadata' => $arr_objectmeta )); $files_uploaded++; } catch (\aws\s3\exception\s3exception $e) { $files_not_uploaded++; }
Comments
Post a Comment