【问题标题】:RequestTimeTooSkewed Error using PHP S3 Class使用 PHP S3 类的 RequestTimeTooSkewed 错误
【发布时间】:2011-10-13 03:29:37
【问题描述】:

这是我的第一个 PHP 项目,所以我真的一点也不了解 PHP。

我正在尝试使用 PHP S3 类将文件上传到 S3 存储桶。一个示例 sn-p 代码昨天还在工作,但是当我今天再次开始使用它时,几乎完全相同的代码停止工作了。

现在我得到了 putObject 函数返回的以下错误:

Warning: S3::putObject(): RequestTimeTooSkewed The difference between the request time and the current time is too large. in /vagrant/LifeInYourWay/S3.php on line 222

我在一些地方读到服务器时间可能会导致错误,所以我将服务器时间更改为 America/New_York 但仍然得到相同的结果。

我拥有的 PHP 代码是:

if(!class_exists('S3')) require_once('S3.php');

// AWS access
if(!defined('awsAccessKey')) define('awsAccessKey', '******');
if(!defined('awsSecretKey')) define('awsSecretKey', '******');

$s3 = new S3(awsAccessKey, awsSecretKey);

$imageName = $_FILES['imageFile']['name'];
$imageTempName = $_FILES['imageFile']['tmp_name'];
$imageLink = $_POST['imageLink'];

if(!strlen($imageLink) || $imageLink == 'http://'){
    //create a new bucket
    $s3->putBucket("widget-images", S3::ACL_PUBLIC_READ);

    //move the file
    $put = $s3->putObject($s3->inputFile($imageTempName), "widget-images", $imageName, S3::ACL_PUBLIC_READ);
    if($put){
        var_dump($put);
        $imageUploaded = true;
    }else{
        $imageUploaded = false;
    }
    echo($imageUploaded);
}else $image = $imageLink;

【问题讨论】:

    标签: php amazon-s3 amazon-web-services


    【解决方案1】:

    您计算机的时钟或时区设置不正确。因为 S3 使用当前时间来验证请求,所以如果您的时钟偏离时间超过 15 分钟,或者您的时区不正确(从而导致小时偏差),您的请求将会失败。

    【讨论】:

    • 谢谢。我更改了时区,但没想到要查看实际时间。休息了大约 18 分钟。
    • 我正在安装本地主机 MAMP。今天早上我上传到 S3 工作,让我的电脑在一天的剩余时间里处于睡眠状态,这开始发生了。重启 apache 没用,但是重启我的电脑就可以了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-01
    • 2021-10-26
    • 2014-11-15
    • 2013-07-09
    • 1970-01-01
    • 2015-09-28
    • 1970-01-01
    相关资源
    最近更新 更多