简体   繁体   中英

Blob SAS URI character decoded when passed as Query parameter to Azure Function app

I wanted to pass the SAS URI of a image file to Azure Functions as query parameters. But when I pass the below URL in GET call, some characters from 'sig' part get decoded https://ABCD.blob.core.windows.net/images/test.jpg?sp=r&st=2021-05-06T11:30:21Z&se=2022-05-06T19:30:21Z&spr=https&sv=2020-02-10&sr=b&sig=JuPyAR%2F5WNeSVXj4G%2Fft9QDMzL%2BtXSywSS375jZpjXQ%3D

The above URL becomes https://ABCD.blob.core.windows.net/images/test.jpg?sp=r&st=2021-05-06T11:30:21Z&se=2022-05-06T19:30:21Z&spr=https&sv=2020-02-10&sr=b&sig=JuPyAR/5WNeSVXj4G/ft9QDMzL+tXSywSS375jZpjXQ=

%2F to / %2B to + %3D to =

Because of this when I try to access the blob, I get error :

System.Private.CoreLib: Exception while executing function: FUNCTIONNAME. System.Net.Requests: The remote server returned an error: (403) Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature..

I am accessing the URI using below code

string image = req.Query["image"];

Before you send the image URL to Azure function as a request param, pls use base64 to encode the whole URL and in your Azure function decode it just as below:

string image = req.Query["image"];

string base64Encoded = image;
string base64Decoded;
byte[] data = System.Convert.FromBase64String(base64Encoded);
base64Decoded = System.Text.ASCIIEncoding.ASCII.GetString(data);
log.LogInformation(image);
log.LogInformation(base64Decoded);

so that you can get the original URL. I have tested on my side, it works for me perfectly:

在此处输入图像描述

Let me know if you have any more questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM