Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
260 views
in Technique[技术] by (71.8m points)

azure - Unable To Set Blob Service Properties

I have an issue with azure storage blob is not returning 206 Partial content for video files.

Problem: videos are fully downloaded(20-40s for 300mb videos) and the seek bar is not working. I am using Laravel and this problem occurs only when I try to retrieve the .mp4 files from Azure Blob Storage. It was working fine when I was storing the media files on the public disk.

A microsoft employee states that changing the x-ms-version to 2011-01-18 or later will fix my issue. LINK to the discussion:

Microsoft have a post related to setting the blob servic properties: HERE

Note their sample for achieving that: https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-service-properties#sample-request-and-response

I am trying to send the request via Postman like this:

PUT https://{account-name}.blob.core.windows.net/?restype=service&comp=properties

Included Headers and Response in Postman: enter image description here

I searched for the error and found this question on SO: The MAC signature found in the HTTP request '...' is not the same as any computed signature

It has an accepted answer but I don't seem to get it. Is there something wrong with my Request/ Authorization header? Or I need to take a different approach?

Thanks in advance!

My code in LARAVEL:

 $date = gmdate('D, d M Y H:i:s GMT');
    $account_name = "xyz";
    $containername = "media";
    $account_key = "access_key";

    $canonicalizedHeaders  = "x-ms-date:$date
x-ms-version:2017-11-09";
    $canonicalizedResource = "/$account_name/$containername
comp:list
restype:container";

    $arraysign = array();
    $arraysign[] = 'GET';                     /*HTTP Verb*/
    $arraysign[] = '';                        /*Content-Encoding*/
    $arraysign[] = '';                        /*Content-Language*/
    $arraysign[] = '';                        /*Content-Length (include value when zero)*/
    $arraysign[] = '';                        /*Content-MD5*/
    $arraysign[] = '';                        /*Content-Type*/
    $arraysign[] = '';                        /*Date*/
    $arraysign[] = '';                        /*If-Modified-Since */
    $arraysign[] = '';                        /*If-Match*/
    $arraysign[] = '';                        /*If-None-Match*/
    $arraysign[] = '';                        /*If-Unmodified-Since*/
    $arraysign[] = '';                        /*Range*/
    $arraysign[] = $canonicalizedHeaders;     /*CanonicalizedHeaders*/
    $arraysign[] = $canonicalizedResource;    /*CanonicalizedResource*/

    $stringtosign = implode("
", $arraysign);

    $signature = 'SharedKey' . ' ' . $account_name . ':' . base64_encode(hash_hmac('sha256', $stringtosign, base64_decode($account_key), true));

    $endpoint = 'https://' . $account_name . '.blob.core.windows.net';
    $url = $endpoint . '/' . $containername . '?restype=container';

    $headers = [
        "x-ms-date:{$date}",
        'x-ms-version:2017-11-09',
        'Accept:application/json;odata=nometadata',
        "Authorization:{$signature}"
    ];

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response  = curl_exec($ch);
    echo curl_error($ch);
    curl_close($ch);
    echo '<pre>';
    print_r($response);
question from:https://stackoverflow.com/questions/66065760/unable-to-set-blob-service-properties

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I can reproduce your error when using Shared key(This problem comes from you give the storage account key instead of the key after signed by HMAC.):

enter image description here

But if I use AD bearer token, then it will be no problem:

enter image description here

Python code to get the bearer token:

import requests
from azure.identity import ClientSecretCredential 

client_id = 'xxx'
tenant_id = 'xxx'
client_secret = 'xxx'

credential = ClientSecretCredential(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret)
accesstoken = str(credential.get_token('https://yourstoragename.blob.core.windows.net/.default'))[19:1282]
print(str(credential.get_token('https://yourstoragename.blob.core.windows.net/.default')))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...