2017-11-22 4 views
0

PHP SDK를 사용하여 원격 URL에서 azure 저장소로 csv를 업로드하려고합니다. 이 오류가 계속 발생하는 것 같습니다. 나는 곱슬 곱슬 함을 사용하여 SDK없이 시도했지만 여전히 같은 오류가 발생합니다.PHP로 Windows Azure 스토리지에 csv 업로드

<?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(); 
} 

캔트이 보인다 :

`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 코드입니다. 어떤 지침은 좋을 것이다

답변

0

오류는 403 auth failed와 관련이 있습니다. 제조업체를 확인하십시오.

  1. 귀하의 계정 이름과 계정 키는 유효하며 만료되지 않습니다. Azure Storage Explorer로 로그인을 시도하거나 Azure 포털을 확인하여이를 확인할 수 있습니다.
  2. Azure Storage에서 키를받은 후에 base64_encode ($ key)가 다시 필요하지 않습니다. Azure Storage에서받은 키는 이미 base64_encoded입니다.
0

인증 문제는 키가 올바르게 설정되지 않은 것과 관련이 있습니다. 왜 인코딩을 결정했는지 확신 할 수는 없지만 스토리지 액세스 키는 제시된대로 정확하게 사용해야합니다.

사실, 전체 연결 문자열은 이미 구성되어 있습니다. 직접 제작할 필요가 없습니다.

관련 문제