1. Bjarne Anker
  2. PowerBuilder
  3. Wednesday, 17 March 2021 22:13 PM UTC

Hi.

 

One of our customers is getting some statistical data from PowerBI, and it's stored in CSV file in an Azure File Storage account.

I can open the URL in Azure Storage Explorer and download the file without any problem, but of course we need to do this in code, in PB2019.

The URL provided is at this format:

https://<accountname>.file.core.windows.net/<foldername>?sp=rl&st=2021-03-16T09:49:45Z&se=2049-12-31T23:00:00Z&sv=2020-02-10&sig=<signature/shared key>&sr=s

My plan is to use this URL in an HttpClient object and store the CSV file in the given folder.

There is no other authorization provided than the shared key (SAS - Shared Access Key).

I need to calculate some sort of Authorization Token using this key, but I cannot seem to figure it out.

 

Has anyone made this type of request work from PB2019?

 

Regards,

 

Bjarne

Maritech

Norway

Francisco Javier García Accepted Answer Pending Moderation
  1. Friday, 10 June 2022 10:32 AM UTC
  2. PowerBuilder
  3. # 1

Hi Bjarne,
I have the same problem as you. I have a URL and a TOKEN and I need to access an Azure File Storage folder
Has it been implemented in PowerBuilder?


Thank you

Comment
There are no comments made yet.
mike S Accepted Answer Pending Moderation
  1. Friday, 10 June 2022 12:54 PM UTC
  2. PowerBuilder
  3. # 2

you use the SAS instead of doing the calculation.  You append the SAS to the url and use the PB HTTP client to download the file or blob pretty much as you have listed there.  azure has their REST api pretty well documented.

However, SAS will typically have an expiration on it.  It should anyway, security etc.  so there is typically a first step of getting the SAS.

You do need to use a couple of MS specific items in the request headers including the api version:

ll_rval = inv_http.setrequestheader("x-ms-date", ls_GMTformattedDate) //DATE
ll_rval = inv_http.setrequestheader("x-ms-version", is_x_ms_version )  //is_x_ms_version = '2020-04-08'

 

you want to generally want to read in chunks because you have no idea how huge the file may be:

do while true
ll_rval = inv_http.ReadData(lblb_NextData, 5242880 ) //5mb chunks //1024*16) - 16K did NOT work very well in PowerServer. 5MB chunks worked better
if ll_rval = 0 then exit // Finish receiving data
if ll_rval < 0 then exit // Error occurred

ablb_file += lblb_NextData
lblb_NextData = lblb_empty
loop

 

what error message do you get?

 

 

The other method of using the security token involves a signing key which is used in a complex calculation of the header values and GMT time.  I did a presentation at elevate about 5 years ago on using azure blob storage and the calculation involved.  Using the signing key requires having it in your app, which is unsecure.  generally you want to use SAS and have a another rest api that provides the sas to your application.  The SAS can/should be locked to an IP address and be set to expire. 

Comment
There are no comments made yet.
mike S Accepted Answer Pending Moderation
  1. Friday, 10 June 2022 12:58 PM UTC
  2. PowerBuilder
  3. # 3

also, i use the blob storage instead of file storage.  I think the REST access is either the same, or pretty much the same.   File storage usually costs a bit more, but it does have the advantage of allowing you to set it up to allow network share access to it.   So you could do a simple fileopen, fileread....

That gets around having to do the REST calls

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.