I have a form set up on my Wordpress site using Gravity Forms. I have found a script to upload the files to my Amazon S3 server.
Unfortunately I keep getting the following error:
The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.
I've looked online and I can see that it needs updating to AWS new authentication methods. I'm not sure how to do this though. Is anyone able to offer me any assistance?
I've included my functions script and a link to the S3.php script i'm using to authenticate.
functions.php
include_once 'inc/S3.php';
//* AWS access info
define( 'awsAccessKey', 'MY ACCESS KEY' );
define( 'awsSecretKey', 'MY SECRET KEY' );
define( 'GFS3_BUCKET', 'MY BUCKET' );
//* Form constants
define( 'FORM_ID', 4 );
define( 'FILE_UPLOAD_FIELD_ID', 1 );
//* Upload the file after form is submitted (Product Edit)
add_action( 'gform_after_submission_' . FORM_ID, 'gf_submit_to_s3', 10, 2 );
function gf_submit_to_s3( $entry, $form ) {
// Bail if there is no file uploaded to the form
if ( empty( $entry[FILE_UPLOAD_FIELD_ID] ) )
return;
// Instantiate the S3 class
$s3 = new S3( awsAccessKey, awsSecretKey );
// Get the URL of the uploaded file
$file_url = $entry[FILE_UPLOAD_FIELD_ID];
// Retreive post variables
$file_name = $_FILES['input_' . FILE_UPLOAD_FIELD_ID]['name'];
/**
* File Permissions
*
* ACL_PRIVATE
* ACL_PUBLIC_READ
* ACL_PUBLIC_READ_WRITE
* ACL_AUTHENTICATED_READ
*/
// Create a new bucket if it does not exist (happens only once)
$s3->putBucket( GFS3_BUCKET, S3::ACL_AUTHENTICATED_READ );
// Parse the URL of the uploaded file
$url_parts = parse_url( $file_url );
// Full path to the file
$full_path = $_SERVER['DOCUMENT_ROOT'] . $url_parts['path'];
// Add the file to S3
$s3->putObjectFile( $full_path, GFS3_BUCKET, $file_name, S3::ACL_AUTHENTICATED_READ );
// Confirmation/Error
if ( $s3->putObjectFile( $full_path, GFS3_BUCKET, $file_name, S3::ACL_AUTHENTICATED_READ ) ) {
printf( 'Your file <strong>%1$s</strong> was successfully uploaded.', $file_name );
} else {
wp_die( __( 'It looks like something went wrong while uploading your file. Please try again. If you continue to experience this problem, please contact the site administrator.' ) );
}
}
S3.php
* @link http://undesigned.org.za/2007/10/22/amazon-s3-php-class
* @version 0.5.0-dev