Search code examples
phpazureyii2azure-storageflysystem

Yii2 Azure Flysystem cannot save error


When I am uploading a file to the Azure FILE Storage I am getting the following error:

in 
E:\WAMP\www\myweb\_protected\vendor\microsoft\windowsazure\WindowsAzure\Common\Internal\Http\Url.php at line 74 – WindowsAzure\Common\Internal\Validate::isTrue(false, 'Provided URL is invalid.')

E:\WAMP\www\allure\_protected\vendor\microsoft\windowsazure\WindowsAzure\Common\Internal\RestProxy.php at line 122 – WindowsAzure\Common\Internal\Http\Url::__construct('https://cG9rYXJuYXZpb282mGQ=.blo...')

The settings that I have in my config file is:

'filesystem' => [
            'class' => 'creocoder\flysystem\AzureFilesystem',
            'accountName' => 'azure-accname',
            'accountKey' => 'some-long-key-A==',
            'container' => 'azure-container',
],

and finally, the code I am calling to save the file is:

if($file = \yii\web\UploadedFile::getInstance($this, 'attachment'))
{
    $stream = fopen($file->tempName, 'r+');
    Yii::$app->filesystem->writeStream($file->name, $stream);
}

Some additional information that might be helpful

  1. running on yii2 advanced framework
  2. webserver: IIS 8.5 on Windows 2012
  3. PHP 5.4.5
  4. composer used for installation
  5. its a azure file system - the error seems to throw error for blob.core.windows.net, where as I am saving data to file.core.windows.net. What changes should I do in config / settings?

Solution

  • According the source code at https://github.com/creocoder/yii2-flysystem/blob/master/src/AzureFilesystem.php#L62, it seems the package encrypt the storage info string into base64 encode before combine them into the connection string. Which makes the strange looking url format in your error message 'https://cG9rYXJuYXZpb282mGQ=.blo...'.

    Please try to set the account info into following format:

    ...   
    'accountName' => base64_decode('azure-accname'),
    'accountKey' => base64_decode('some-long-key-A=='),
    ...
    

    Any further concern, please feel free to let me know.