1. Zhang JX
  2. PowerBuilder
  3. Friday, 27 January 2023 01:33 AM UTC

Hi all,

We are facing issue with documents/files accessing via ftp after enabling Azure Fortigate Firewall.

The alternative solution is either to use SFTP or moving to Azure Blob Storage then dealling with those application with attachment documents.

I am looking for a simple way to work with Azure Blob Storage account.

Below screen is from ChatGPT answer, it is simple and straightforward if compare to Azure Blob Storage API method, but ChatGPT failed to advise how to get the AzureBlobClient library.

Appreciate your advice if anyone knew about this method.

 

Thank you. JX

Accepted Answer
mike S Accepted Answer Pending Moderation
  1. Friday, 27 January 2023 14:52 PM UTC
  2. PowerBuilder
  3. # Permalink

who told you that code is powerbuilder?

 

 

Comment
  1. Zhang JX
  2. Sunday, 29 January 2023 08:13 AM UTC
Thank you Mike.

Yes, i would like to try PB http client API call directly. please advise the sample coding.

Regards, JX
  1. Helpful
  1. mike S
  2. Tuesday, 31 January 2023 18:19 PM UTC
the api is here:

https://learn.microsoft.com/en-us/rest/api/storageservices/put-blob



its just calling the api's that you need using the http client.

If you plan on using SAS for security, then you will need an api to get the sas signature. one way is use an azure function to generate it.

  1. Helpful 1
  1. Zhang JX
  2. Sunday, 5 February 2023 07:38 AM UTC
Thank you, Mike S.
  1. Helpful
There are no comments made yet.
Zhang JX Accepted Answer Pending Moderation
  1. Sunday, 5 February 2023 07:59 AM UTC
  2. PowerBuilder
  3. # 1

To all, 

Thanks Mike's hints on API method, I am able to access Azure Blob Storage from PowerScript.

To share some points which think will help others as well:

1. For Token, it is not either to construct the signature string, so I choosed to use SAS option, which make sense since I am coding for appliction access.

2. To get the SAS Token, access from AzureBlobStorage instance >> Shared access signature >> Shared Access Signature >> Container >> Set the valid period >> Generate SAS and connection string >> copy the SAS token

3. To use httpclient PUT method to upload a file, please replace <...> with your own name/string.

long ll_FileNum
blob blb_file
integer li_rc
HTTPClient lnv_HttpClient

string ls_endpoint, ls_url, ls_account, ls_container
string ls_file,ls_updfile, ls_encoded
integer li_ResponseStatusCode = 0
string ls_ResponseBody = ''
string ls_ResponseStatusMessage = ''
string ls_PathName, ls_FileName

if GetFileOpenName ("Open", ls_PathName, ls_FileName, "PDF") < 1 then
ls_FIle = 'c:\Appn\temp\Tax Invoice format (RM)_Brother.xlsx' //For Testing by default
end if

ls_account = '<...>'
ls_container = 'attachment'
ls_endpoint = 'https://'+ls_account+'.blob.core.windows.net/'+ls_container
ls_updfile = '/DYI/'+ls_FileName

ls_url = ls_endpoint +ls_updfile+ '?sv=2021-06-08&ss=bfqt&srt=sco&sp=rwdlacupiytfx&se=2024-01-30T13:11:46Z&st=2023-01-30T05:11:46Z&spr=https&sig=DLvA7<......>bqntRFW%3D'

ls_file = ls_PathName
ll_FileNum = FileOpen(ls_file, StreamMode!)
if ll_FileNum > 0 then
FileReadEx(ll_FileNum, blb_file)
FileClose(ll_FileNum)
else
MessageBox('File Error', 'Error Opening Filename ' + ls_file)
return
end if

// Send the request
Lnv_HttpClient = create HttpClient
Lnv_HttpClient.SetRequestHeader("Content-Type", "application/json")
Lnv_HttpClient.SetRequestHeader("x-ms-blob-type", "BlockBlob")
Lnv_HttpClient.SetRequestHeader("host", "<...>.blob.core.windows.net")

li_rc = Lnv_HttpClient.sendrequest( "PUT",ls_url,blb_file )

// obtain the response data
if li_rc = 1 then
li_ResponseStatusCode = Lnv_HttpClient.GetResponseStatusCode()
ls_ResponseStatusMessage = Lnv_HttpClient.GetResponseStatusText()

if li_ResponseStatusCode = 201 then
ls_ResponseBody= ls_PathName +' / FileName: '+ls_FileName
MessageBox('Upload Successfull', ls_ResponseBody)
else
MessageBox('Upload Failed', ls_ResponseBody)
end if
else
MessageBox('HTTP Error', 'Error calling ' + ls_endpoint + '. Return Code ' + string(li_rc))
end if

Result as follow:

Regards, JX

Comment
  1. Miguel Leeuwe
  2. Sunday, 5 February 2023 13:35 PM UTC
Thank you JX for sharing this!
  1. Helpful
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.