php - "Request date header too old"将大量文件上传到 blob 存储时发生错误

标签 php azure azure-blob-storage

我的服务器上有大量图像文件(大约 900,000 个),我正在使用适用于 PHP 的 Azure 客户端库进行循环并将文件上传到 Azure Blob 存储。我的上传脚本运行良好大约 2 天,然后突然停止并输出以下错误。

Oct 19 01:28:14 ik1-315-17878 php: PHP Fatal error: Uncaught exception 'MicrosoftAzure\Storage\Common\Exceptions\ServiceException' with message 'Fail:#012Code: 403#012Value: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.#012details (if any): AuthenticationFailedServer failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.#012RequestId:e7f247d6-001e-0022-142e-48abcc000000#012Time:2017-10-18T16:28:14.4980791ZRequest date header too old: 'Wed, 18 Oct 2017 16:12:27 GMT'.' in /home/t-matsumoto/GAZOU/vendor/microsoft/azure-storage/src/Common/Internal/ServiceRestProxy.php:486#012Stack trace:#012#0 /home/t-matsumoto/GAZOU/vendor/microsoft/azure-storage/src/Common/Internal/ServiceRestProxy.php(404): MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy::throwIfError(Object(GuzzleHttp\Psr7\Respon in /home/t-matsumoto/GAZOU/vendor/microsoft/azure-storage/src/Common/Internal/ServiceRestProxy.php on line 486

我已经搜索了原因,很可能是因为我的脚本发出该请求时的时间戳与 Azure 收到请求时的时间戳相比太旧。根据上面的错误信息,发出请求的时间是“Wed, 18 Oct 2017 16:12:27 GMT”,接收请求的时间是“2017-10-18T16:28:14.4980791Z”(大约晚了15分钟) 。但我仍然不明白的是,为什么我的脚本运行了一段时间没有错误,然后突然发生错误。谁能向我解释一下这个现象和解决方案,使我的脚本稳定运行,没有错误。

我的 php 脚本如下所示

    require_once 'vendor/autoload.php';

    use MicrosoftAzure\Storage\Common\ServicesBuilder;
    use MicrosoftAzure\Storage\Common\ServiceException;

    $connectionString = "DefaultEndpointsProtocol=http;AccountName=<accountNameHere>;AccountKey=<accountKeyHere>";

    // Create blob REST proxy.
    $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);

foreach ($myListFiles as $filename) {
    $content = fopen($filename, "r");
    $blob_name = "myblob";

    //Upload blob
    $blobRestProxy->createBlockBlob("mycontainer", $blob_name, $content);
}

我从此链接上传了示例脚本 https://learn.microsoft.com/en-us/azure/storage/blobs/storage-php-how-to-use-blobs

最佳答案

我认为@Gaurav Mantri 已经回答了你的问题:

Azure storage error using Python SDK

<小时/>

但由于您有大量图像文件要上传到 Azure 存储,我建议使用 AzCopy要做到这一点。 AzCopy 是一个命令行实用程序,旨在使用具有最佳性能的简单命令将数据复制到 Microsoft Azure Blob、文件和表存储以及从 Microsoft Azure Blob、文件和表存储复制数据。

关于php - "Request date header too old"将大量文件上传到 blob 存储时发生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46825671/

相关文章:

json - 在部署级别配置资源组和azure功能

azure - 如何在Azure API管理上分离开发和生产环境?

.net - Flush 和 Write 调用的特定组合会损坏通过 OpenWrite 使用的 BlockBlob

php - 尝试检索最小值时出现 mysql "select"问题

PHP 和 MySQL 显示之前的位置

php - 如何使用 PDO 语句将组合数组插入 mysql 表

python-3.x - Python Azure sdk - 启用磁盘加密

php - 我可以根据屏幕尺寸显示不同的表格吗?

c# - 仅使用缩略图创建器 Azure Function 处理图像

hadoop - Kafka Connect HDFS 接收器与 Azure Blob 存储