使用php将csv上传到windows azure存储

问题描述 投票:0回答:2

尝试使用PHP SDK将csv从远程URL上传到azure存储。我似乎一直在犯这个错误。我没有使用curl的SDK尝试过它,我仍然得到相同的错误。

`PUT resulted in a `403 Server failed to authenticate the request. 
Make sure the value of Authorization header is formed correctly including the signature.` response: 
<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate (truncated...) 
in C:\wamp64\www\azurescript\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 113

这是我正在使用的PHP代码:

<?php

require_once 'vendor/autoload.php';

use MicrosoftAzure\Storage\Common\ServicesBuilder;
use MicrosoftAzure\Storage\Common\ServiceException;
use MicrosoftAzure\Blob\Models\SetBlobPropertiesOptions;


$key = base64_encode("abc");

$connectionString = "DefaultEndpointsProtocol=https;AccountName=username;AccountKey={$key}";

$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);

// Grab the csv from the remote url
$csv = fopen("http://www.xxxxx.com/wp-cron.phpexport_hash=yyyyyy&export_id=1&action=get_data", "r");
$blobName = "test";

try    {
    // Upload the blob
    $blobRestProxy->createBlockBlob("container", $blobName, $csv);
}
catch(ServiceException $e){

    // Errors
    $code = $e->getCode();
    $errorMessage = $e->getMessage();
}

似乎不是这样的。一些指导会很好

php azure azure-storage
2个回答
0
投票

该错误与403 auth失败有关。请确保:

  1. 您的帐户名称和帐户密钥有效且未过期。您可以通过尝试使用Azure Storage Explorer进行登录来确认这一点,也可以在Azure门户上进行检查。
  2. 从Azure存储接收密钥后,您不再需要base64_encode($ key)。从Azure存储接收的密钥已经是base64_encoded。

0
投票

身份验证问题与您的密钥未正确设置有关。不确定为什么你决定对它进行编码,但是......你需要使用完全按照它呈现给你的存储访问密钥。

事实上,整个连接字符串已经为您构建;不需要自己构建它。

© www.soinside.com 2019 - 2024. All rights reserved.