cURL and Azure BLOB with SAS – HTTP header that’s mandatory for this request is not specified

I’ve reviewed the information at:

  • https://docs.microsoft.com/en-us/rest/api/storageservices/put-blob
  • https://docs.microsoft.com/en-us/rest/api/storageservices/service-sas-examples

As far as I can tell I am complying becuase I am posting the SAS in the URL.

Here is my simple test script:

#!/bin/bash

DATE_NOW=$(date -Ru | sed 's/+0000/GMT/')
AZ_VERSION="2018-03-28"
AZ_BLOB_URL="https://XXXXXXXX.blob.core.windows.net"
AZ_BLOB_CONTAINER="XXXXXX"
AZ_BLOB_TARGET="${AZ_BLOB_URL}/${AZ_BLOB_CONTAINER}/"
AZ_SAS_TOKEN="?sv=2017-11-09&ss=b&srt=o&sp=rwlac&se=2021-11-06T01:05:33Z&st=2018-11-09T17:05:33Z&sip=192.0.2.0-192.0.2.254&spr=https&sig=XXXXXXXXXX"

curl -v -X PUT -H "Content-Type: application/octet-stream" -H "x-ms-date: ${DATE_NOW}" -H "x-ms-version: ${AZ_VERSION}" --data-binary "@/home/test/test" "${AZ_BLOB_TARGET}test${AZ_SAS_TOKEN}"

Running that yields:

> PUT /XXXX/XXXXX?sv=2017-11-09&ss=b&srt=o&sp=rwlac&se=2021-11-06T01:05:33Z&st=2018-11-09T17:05:33Z&sip=192.0.2.0-192.0.2.254&spr=https&sig=XXXXXXXXXX" HTTP/1.1
> Host: XXXXX.blob.core.windows.net
> User-Agent: curl/7.60.0
> Accept: */*
> Content-Type: application/octet-stream
> x-ms-date: Sat, 10 Nov 2018 17:48:06 GMT
> x-ms-version: 2018-03-28
> Content-Length: 14
> 
* upload completely sent off: 14 out of 14 bytes
< HTTP/1.1 400 An HTTP header that's mandatory for this request is not specified.
< Content-Length: 295
< Content-Type: application/xml
< Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
< x-ms-request-id: 69b144ec-b01e-0112-651d-791ccd000000
< x-ms-version: 2018-03-28
< x-ms-error-code: MissingRequiredHeader
< Date: Sat, 10 Nov 2018 17:48:06 GMT
< 
MissingRequiredHeaderAn HTTP header that's mandatory for this request is not specified.
RequestId:69b144ec-b01e-0112-651d-791ccd000000

Leave a Reply

Your email address will not be published. Required fields are marked *