Marthaj
asked on
PHP 7 and returning the status code from AWS upload to a bucket
I have been searching to find out how I can retrieve the numeric status code after I upload a file to a AWS S3 bucket. I can retrieve the results of the ObjectURL but I need the numeric status code. I know if it returns 200, all is well. If not, then I want to take a different route.
I have seen examples for large files, streaming, multipart etc.
But these are very small files and I can not see using the uploader object nor multipart examples for these files.
Below is my code -
thank you in advance and any help appreciated.
I have seen examples for large files, streaming, multipart etc.
But these are very small files and I can not see using the uploader object nor multipart examples for these files.
Below is my code -
thank you in advance and any help appreciated.
Function RtnAWSUpload($wrkProdFileLocation,$wrkAWSFileLocation)
{
$bucket = 'somebucket';
$keyname = 'somekey';
$secretkey = 'someprvkey'; // PRVKEY
// echo '<BR><BR>AT AWS UPLOAD RTN';
$s3 = new S3Client([
'version' => 'latest',
'region' => 'us-east-2',
'credentials' => array('key'=>$keyname,
'secret'=>$secretkey)
]);
try {
// UPLOAD FILE TO AWS BUCKET
$result = $s3->putObject([
'Bucket' => $bucket,
'Key' => $wrkAWSFileLocation,
'SourceFile' => $wrkProdFileLocation,
'ACL' => 'public-read'
]);
// PRINT URL TO OBJECT
//echo '<BR><BR>AWS FILE UPLOAD RESULT: ' . $result['ObjectURL'] . PHP_EOL;
$strAWSUploadResult = $result['ObjectURL']; // need to return the numeric status code instead of message)
$_SESSION['NbrOfFilesUploaded'] = ($_SESSION['NbrOfFilesUploaded'] + 1);
} catch (S3Exception $e) {
echo $e->getAwsErrorCode() . PHP_EOL;
echo $e->getMessage() . PHP_EOL;
}
return $strAWSUploadResult;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.