phpazureazure-storage-files

Azure Storage PHP client fails to authenticate when uploading streamed file content


I'm using the azure-storage-php library to copy files to an Azure Storage Fileshare.

Moving files to the fileshare works in general, but when using streamed file content, I get an authentication error:

Fail:
Code: 403
Value: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
details (if any): <?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:070c24e7-ABCD-EFGH-7f8e6d000000
Time:2019-10-10T11:45:35.8832342Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request 'X+WJOUaKHhOABCDEFGHIJKLMNOPQRSTUVWXYZe5Iu2k=' is not the same as any computed signature. Server used following string to sign: 'PUT


568340

text/csv
Thu, 10 Oct 2019 11:45:35 GMT





x-ms-range:bytes=0-568339
x-ms-request-id:5d9f19dfd2dae
x-ms-version:2016-05-31
x-ms-write:Update
/username/file-share-name/myFile.csv
comp:range'.</AuthenticationErrorDetail></Error>

I've already made sure that system time is in sync, as some people had issues with this.

The file even is created on the storage and filled with lots of lines of

0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000

I'm using https://github.com/thephpleague/flysystem as an abstraction layer. To open the stream I both tried using $stream = fopen('filePath.csv', 'rb') and $flysystem->readStream('localFilesystem', 'filePath.csv');


Solution

  • After a hint from Gaurav Mantri I figured that the error only occurs when the size of the streamed file is below a certain threshold. In my case this was about 4MB.

    Uploading streamed files < 4MB resulted in the described error.

    Uploading streamed files > 4MB works just fine.

    Unfortunately I don't have an explanation why this happens. I now use a workaround to check the file size before uploading it and then either use a direct upload or use a stream for larger files.