3

我在我的 Wordpress 网站上使用 Gravity Forms 设置了一个表单。我找到了将文件上传到我的 Amazon S3 服务器的脚本。

不幸的是,我不断收到以下错误:

不支持您提供的授权机制。请使用 AWS4-HMAC-SHA256。

我在网上查看过,我可以看到它需要更新到 AWS 新的身份验证方法。我不确定如何做到这一点。有人可以为我提供任何帮助吗?

我已经包含了我的函数脚本和我用来进行身份验证的 S3.php 脚本的链接。

函数.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
4

0 回答 0