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
Yes, i would like to try PB http client API call directly. please advise the sample coding.
Regards, JX
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.