![]() |
Chilkat • HOME • Android™ • AutoIt • C • C# • C++ • Chilkat2-Python • CkPython • Classic ASP • DataFlex • Delphi DLL • Go • Java • Node.js • Objective-C • PHP Extension • Perl • PowerBuilder • PowerShell • PureBasic • Ruby • SQL Server • Swift • Tcl • Unicode C • Unicode C++ • VB.NET • VBScript • Visual Basic 6.0 • Visual FoxPro • Xojo Plugin
(Visual FoxPro) Use an Azure Service SASShows how to use an Azure Service SAS. (In this case, it is an SAS for a blob.)
LOCAL loRest LOCAL lnBTls LOCAL lnPort LOCAL lnBAutoReconnect LOCAL lnSuccess LOCAL loSbToken LOCAL loBinData LOCAL loSbResponse * Azure Blob Service Example: Upload binary bytes to a block blob. * This uses a Service SAS for Authorization. * This example requires the Chilkat API to have been previously unlocked. * See Global Unlock Sample for sample code. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Rest') loRest = CreateObject('Chilkat.Rest') * Connect to the Azure Storage Blob Service lnBTls = 1 lnPort = 443 lnBAutoReconnect = 1 * In this example, the storage account name is "chilkat". lnSuccess = loRest.Connect("chilkat.blob.core.windows.net",lnPort,lnBTls,lnBAutoReconnect) IF (lnSuccess <> 1) THEN ? loRest.LastErrorText RELEASE loRest CANCEL ENDIF * ---------------------------------------------------------------------------------------------- * The code above this comment could be placed inside a function/subroutine within the application * because the connection does not need to be made for every request. Once the connection is made * the app may send many requests.. * ---------------------------------------------------------------------------------------------- * Note: The application does not need to explicitly set the following * headers: Content-Length, x-ms-date, Authorization. These headers * are automatically set by Chilkat. * Let's load a previously computed Azure Storage Account SAS token and use it. * See How to Create an Azure Service SAS * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbToken = CreateObject('Chilkat.StringBuilder') lnSuccess = loSbToken.LoadFile("qa_data/tokens/azureStorageServiceSas.txt","utf-8") IF (lnSuccess <> 1) THEN ? "Failed to load SAS token." RELEASE loRest RELEASE loSbToken CANCEL ENDIF * Add the Shared Access Signature query params for authorization. loRest.AddQueryParams(loSbToken.GetAsString()) * IMPORTANT: Make sure to set the x-ms-blob-type header: lnSuccess = loRest.AddHeader("x-ms-blob-type","BlockBlob") * IMPORTANT: Make sure to add the x-ms-date header. * When the header name is "x-ms-date", Chilkat will recognize the keyword "NOW" * and will substitute the current system date/time formatted as required by Microsoft. lnSuccess = loRest.AddHeader("x-ms-date","NOW") * For this example, we'll just load a JPG file into memory.. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.BinData') loBinData = CreateObject('Chilkat.BinData') lnSuccess = loBinData.LoadFile("qa_data/jpg/starfish.jpg") IF (lnSuccess <> 1) THEN ? "Failed to load JPG file." RELEASE loRest RELEASE loSbToken RELEASE loBinData CANCEL ENDIF * Note: The maximum size of a block blob created by uploading in a single step is 64MB. * For larger files, the upload must be broken up into blocks. There is another Chilkat example for that.. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbResponse = CreateObject('Chilkat.StringBuilder') lnSuccess = loRest.FullRequestBd("PUT","/mycontainer/starfish.jpg",loBinData,loSbResponse) IF (lnSuccess <> 1) THEN ? loRest.LastErrorText RELEASE loRest RELEASE loSbToken RELEASE loBinData RELEASE loSbResponse CANCEL ENDIF * When successful, the Azure Storage service will respond with a 201 response status code, * with no response body. IF (loRest.ResponseStatusCode <> 201) THEN * Examine the request/response to see what happened. ? "response status code = " + STR(loRest.ResponseStatusCode) ? "response status text = " + loRest.ResponseStatusText ? "response header: " + loRest.ResponseHeader ? "response body (if any): " + loSbResponse.GetAsString() ? "---" ? "LastRequestStartLine: " + loRest.LastRequestStartLine ? "LastRequestHeader: " + loRest.LastRequestHeader ? "Failed." RELEASE loRest RELEASE loSbToken RELEASE loBinData RELEASE loSbResponse CANCEL ENDIF ? "Success." RELEASE loRest RELEASE loSbToken RELEASE loBinData RELEASE loSbResponse |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.