而上传图像到amazon s3服务器得到InvalidAccessKeyId错误如何解决这个问题


while uploading images to amazon s3 server getting InvalidAccessKeyId error how to solve this?

我尝试将图像上传到amazon S3服务器,但显示错误消息

使用未定义的常量CURL_SSLVERSION_TLSv1 -假设'CURL_SSLVERSION_TLSv1',S3::putBucket(chlogo1, public-read,): [InvalidAccessKeyId]您提供的AWS AccessKeyId在我们的记录中不存在。和S3::putObject(): [InvalidAccessKeyId]您提供的AWS AccessKeyId在我们的记录中不存在。

这是我的代码

            if (!class_exists('S3'))require_once('S3.php');
        //AWS access info
        if (!defined('awsAccessKey')) define('awsAccessKey', 'my_access_key');
        if (!defined('awsSecretKey')) define('awsSecretKey', 'my_secret_key');
        //instantiate the class
        $s3 = new S3(awsAccessKey, awsSecretKey);
                        //retreive post variables
        $fileName = $_FILES['logo']['name'];
        $fileTempName = $_FILES['logo']['tmp_name'];
        //create a new bucket
        $s3->putBucket("chlogo1", S3::ACL_PUBLIC_READ);
        //move the file
        if ($s3->putObjectFile($fileTempName, "chlogo1", $fileName, S3::ACL_PUBLIC_READ)) {
            echo "<strong>We successfully uploaded your file.</strong>";
        }else{
            echo "<strong>Something went wrong while uploading your file... sorry.</strong>";
        }

如果您正在使用codeigniter,只需添加S3库并使用下面的代码,它将帮助您

        $this->load->library('s3');
    $name = $_FILES['logo']['name'];
    $size = $_FILES['logo']['size'];
    $tmp = $_FILES['logo']['tmp_name'];
    $bucket = 'chlogo1';
    $this->s3->putObjectFile($tmp, $bucket , $name, S3::ACL_PUBLIC_READ)

获取您的访问密钥和秘密密钥并将其添加到配置文件夹

中的s3.php中
$config['access_key'] = "xxxxxxxxxxxxxx";
$config['secret_key'] = "xxxxxxxxxxxxxx";