<?php // TODO Enter your AWS credentials define('AWS_ACCESS_KEY', 'AKIAIUGZZ6GQ5EGV62CQ'); define('AWS_SECRET', 'I0pMNDz07+afysocM4ZqLAsAOr0UCUNGDQEMyWd8'); // TODO Enter your bucket and region details (see details below) $s3FormDetails = getS3Details('wermfiles', 'us-east-1'); /** * Get all the necessary details to directly upload a private file to S3 * asynchronously with JavaScript. * * @param string $s3Bucket your bucket's name on s3. * @param string $region the bucket's location, see here for details: http://amzn.to/1FtPG6r * @param string $acl the visibility/permissions of your file, see details: http://amzn.to/18s9Gv7 * * @return array ['url', 'inputs'] the forms url to s3 and any inputs the form will need. */ function getS3Details($s3Bucket, $region, $acl = 'private') { // Options and Settings $algorithm = "AWS4-HMAC-SHA256"; $service = "s3"; $date = gmdate('Ymd\\THis\\Z'); $shortDate = gmdate('Ymd'); $requestType = "aws4_request"; $expires = '86400'; // 24 Hours $successStatus = '201'; $url = '//' . $s3Bucket . '.' . $service . '.amazonaws.com'; //this line caused me such a huge problem, it seems as if taking out region made it work. //$url = '//' . $s3Bucket . '.' . $service . '-' . $region . '.amazonaws.com';
<?php // TODO Enter your AWS credentials define('AWS_ACCESS_KEY', ''); define('AWS_SECRET', ''); // TODO Enter your bucket and region details (see details below) $s3FormDetails = getS3Details('', ''); /** * Get all the necessary details to directly upload a private file to S3 * asynchronously with JavaScript. * * @param string $s3Bucket your bucket's name on s3. * @param string $region the bucket's location, see here for details: http://amzn.to/1FtPG6r * @param string $acl the visibility/permissions of your file, see details: http://amzn.to/18s9Gv7 * * @return array ['url', 'inputs'] the forms url to s3 and any inputs the form will need. */ function getS3Details($s3Bucket, $region, $acl = 'private') { // Options and Settings $algorithm = "AWS4-HMAC-SHA256"; $service = "s3"; $date = gmdate('Ymd\\THis\\Z'); $shortDate = gmdate('Ymd'); $requestType = "aws4_request"; $expires = '86400'; // 24 Hours $successStatus = '201'; $url = '//' . $s3Bucket . '.' . $service . '-' . $region . '.amazonaws.com'; // Step 1: Generate the Scope $scope = [AWS_ACCESS_KEY, $shortDate, $region, $service, $requestType];
/** * Serialize an array * @return multitype: */ function getJsonData() { $var = get_object_vars($this); foreach ($var as &$value) { if (is_object($value) && method_exists($value, 'getJsonData')) { $value = $value->getJsonData(); } } return $var; } // TODO Enter your bucket and region details (see details below) $s3FormDetails = getS3Details(Yii::app()->params['bucket'], Yii::app()->params['region']); /** * Get all the necessary details to directly upload a private file to S3 * asynchronously with JavaScript. * * @param string $s3Bucket your bucket's name on s3. * @param string $region the bucket's location, see here for details: http://amzn.to/1FtPG6r * @param string $acl the visibility/permissions of your file, see details: http://amzn.to/18s9Gv7 * * @return array ['url', 'inputs'] the forms url to s3 and any inputs the form will need. */ function getS3Details($s3Bucket, $region, $acl = 'public-read') { // Options and Settings $algorithm = "AWS4-HMAC-SHA256"; $service = "s3";