I am puzzled and melancholy over the discontinuance of some libraries.
I wanna upload text files to Azure Blob Storage.But this function can’t works.
private static function output($path, $text): bool
{
$accountName = config('filesystems.disks.azure.account_name');
$containerName = config('filesystems.disks.azure.container_name');
$sasToken = config('filesystems.disks.azure.sas_token');
$uri = "https://{$accountName}.blob.core.windows.net/{$containerName}/{$path}";
$version = '2024-05-04';
$checkUri = "{$uri}?{$sasToken}";
$checkResponse = Http::withHeaders([
'x-ms-version' => $version,
'x-ms-date' => gmdate('D, d M Y H:i:s T'),
])->head($checkUri);
if ($checkResponse->status() == 404) {
$createUri = "{$uri}?{$sasToken}";
$createResponse = Http::withHeaders([
'x-ms-blob-type' => 'AppendBlob',
'x-ms-date' => gmdate('D, d M Y H:i:s T'),
'x-ms-version' => $version,
])->put($createUri);
if (!$createResponse->successful()) {
throw new Exception('Failed to create new blob: ' . $createResponse->body());
}
}
$appendUri = "{$uri}?comp=appendblock&{$sasToken}";
$response = Http::withHeaders([
'Content-Type' => 'application/octet-stream',
'x-ms-date' => gmdate('D, d M Y H:i:s T'),
'x-ms-version' => $version,
])->put($appendUri, $text);
if ($response->successful()) {
return true;
} else {
throw new Exception('Failed to append content: ' . $response->body());
}
}
Error message
I do not know the cause of this error.
Failed to create new blob: <?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidHeaderValue</Code><Message>The value for one of the HTTP headers is not inn the correct format.
Time:2024-05-08T02:04:08.7165841Z</Message><HeaderName>Content-Length</HeaderName><HeaderValue>2</HeaderValue></Error>
1