I am getting error while trying to upload a file to Azure Blob Storage using SAS link. Its an authentication error complaining about empty sp attribute. The wierd thing is Sp element is present in SAS Url.
It cannot be a permission issue as I am able to upload the file using the same SAS URL using ADF.
Url
BlobEndpoint=https://####.blob.core.windows.net/####?sp=racwdl&st=2021-12-08T01:14:01Z&se=2022-02-28T09:14:01Z&spr=https&sv=2020-08-04&sr=c&sig=####
Details of error
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:ed57ec28-f01e-00a9-79d2-ebcfc2000000 Time:2021-12-08T01:22:40.1147833Z Status: 403 (Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.) ErrorCode: AuthenticationFailed
Additional Information: AuthenticationErrorDetail: sp is mandatory. Cannot be empty
Content:
AuthenticationFailed
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:ed57ec28-f01e-00a9-79d2-ebcfc2000000 Time:2021-12-08T01:22:40.1147833Zsp is mandatory. Cannot be emptyHeaders: x-ms-request-id: ed57ec28-f01e-00a9-79d2-ebcfc2000000 x-ms-error-code: AuthenticationFailed Content-Length: 407 Content-Type: application/xml Date: Wed, 08 Dec 2021 01:22:39 GMT Server: Microsoft-HTTPAPI/2.0
Code
Stream file = new FileStream(fileToUpload, FileMode.Open);
var blobServiceClient1 = new BlobServiceClient(endpointString);
var containerRef = blobServiceClient1.GetBlobContainerClient("dropoff-commissionstatements");
var blob1 = containerRef.GetBlobClient("TDM_FINAL_102449_13092021_COMMSTMT_AR_TAL_D95337.csv");
string file_extension = Path.GetExtension(fileToUpload);
string filename_withExtension = Path.GetFileName(fileToUpload);
blob1.Upload(file);
CodePudding user response:
Please try by changing your connection string to something like:
BlobEndpoint=https://####.blob.core.windows.net/####; SharedAccessSignature=sp=racwdl&st=2021-12-08T01:14:01Z&se=2022-02-28T09:14:01Z&spr=https&sv=2020-08-04&sr=c&sig=####
For more details, please see this link: https://docs.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string#create-a-connection-string-using-a-shared-access-signature.