Auto Import File from Azure Storage to Cloud BC

julkifli33julkifli33 Member Posts: 1,092
Hi All,
does anyone ever customize auto import file from Azure Storage to cloud BC?
is that possible?
Please advise and share.
Thanks before

Best Answer

  • ftorneroftornero Member Posts: 524
    Answer ✓
    Hello @julkifli33,

    You need to change these two lines:
    urlPath := GetAccountSharedResource() + '/' + GetAdditionalFolderPath + '?comp=list';
    CanonicalizedResource := StrSubstNo('/%1/%2', GetAccountName(), urlPath);
    

    With these:
    urlPath := GetAccountSharedResource() + '/' + GetAdditionalFolderPath + '?comp=list&restype=directory';
    CanonicalizedResource := ConvertStr(StrSubstNo('/%1/%2', GetAccountName(), urlPath), '?=&', cha + ':' + cha);
    

    And you get back and XML with the information.

    Regards

Answers

  • julkifli33julkifli33 Member Posts: 1,092
    I want to read the files from 1 folder with this code
       procedure ReadAzureStorageDirectory()
        var
            requestMethod: Text;
            request: HttpRequestMessage;
            RequestHeader: HttpHeaders;
            hhtpres: HttpResponseMessage;
            canonicalizedResource: Text;
            canonicalizedHeaders: Text;
            urlPath: Text;
            client: HttpClient;
            content: HttpContent;
            ContentHeaders: HttpHeaders;
            test: Boolean;
            authorizationHeader: Text;
            stringToSign: Text;
            msVersion: Text;
            cha: Text[1];
            contenttype: Text;
            contentLength: Integer;
            res: Text;
            keyss: Text;
            dateInRfc1123Format: Text;  // <------------ Changed
            //EncryptionManagement: Codeunit "Encryption Management";
            EncryptionManagement: Codeunit "Cryptography Management";  // <------------ Changed BC15    
            uri: Text;
            Range: Text;
            InStr: InStream;
            ResponseText: Text;
        begin
            cha[1] := 10;
            msVersion := '2020-02-10';
            keyss := GetAccountAccessKey();
            dateInRfc1123Format := GetUTCDateTimeText(); // <------------ Changed
            requestMethod := 'GET';
    
            urlPath := GetAccountSharedResource() + '/' + GetAdditionalFolderPath + '?comp=list';
            CanonicalizedResource := StrSubstNo('/%1/%2', GetAccountName(), urlPath);
            CanonicalizedHeaders := 'x-ms-date:' + dateInRfc1123Format + Format(cha) +
                                    'x-ms-version:' + msVersion;
    
            stringToSign := (requestMethod + Format(cha) +
                             Format(cha) + //Content-Encoding + "\n" +  
                             Format(cha) + //Content-Language + "\n" +  
                             Format(cha) + //Content-Length + "\n" +  
                             Format(cha) + //Content-MD5 + "\n" +
                             Format(cha) + //Content-Type + "\n" +  
                             Format(cha) + //Date + "\n" +  
                             Format(cha) + //If-Modified-Since + "\n" +  
                             Format(cha) + //If-Match + "\n" + 
                             Format(cha) + //If-None-Match + "\n" +  
                             Format(cha) + //If-Unmodified-Since + "\n" +  
                             Format(cha) + //Range + "\n" +  
                             canonicalizedHeaders + Format(cha) + // <------------ Changed
                             canonicalizedResource);
    
            authorizationHeader := 'SharedKey ' + GetAccountName() + ':' + EncryptionManagement.GenerateBase64KeyedHashAsBase64String(stringToSign, keyss, 2);
            uri := StrSubstNo('https://%1.file.core.windows.net/%2', GetAccountName(), urlPath);
            request.SetRequestUri(uri);
            request.Method := requestMethod;
            RequestHeader.Clear();
            request.GetHeaders(RequestHeader);
            RequestHeader.Add('Authorization', authorizationHeader);
            RequestHeader.Add('x-ms-date', dateInRfc1123Format);
            RequestHeader.Add('x-ms-version', msVersion);
    
            client.Send(request, hhtpres);
            if not hhtpres.IsSuccessStatusCode then
                Error(hhtpres.ReasonPhrase)
            else begin
                hhtpres.Content.ReadAs(ResponseText);
                message('%1', ResponseText);
            end;
        end;
    

    but it keep get me the authentication error
    tw9bwro84am2.png
  • SanderDkSanderDk Member Posts: 502
    edited 2021-09-21
    @julkifli33
    I have not done it myself but MS have created a Tech samle to communicate with Azure Storage.
    Perhaps this can help you:
    https://github.com/microsoft/BCTech/tree/master/samples/AzureStorage

    For help, do not use PM, use forum instead, perhaps other people have the same question, or better answers.
  • julkifli33julkifli33 Member Posts: 1,092
    Hi @SanderDk
    thanks for the link.
    but i think this one is only for blob storage.
    actually i need for file storage
    f2qmxfj5dywa.png
  • ftorneroftornero Member Posts: 524
    Answer ✓
    Hello @julkifli33,

    You need to change these two lines:
    urlPath := GetAccountSharedResource() + '/' + GetAdditionalFolderPath + '?comp=list';
    CanonicalizedResource := StrSubstNo('/%1/%2', GetAccountName(), urlPath);
    

    With these:
    urlPath := GetAccountSharedResource() + '/' + GetAdditionalFolderPath + '?comp=list&restype=directory';
    CanonicalizedResource := ConvertStr(StrSubstNo('/%1/%2', GetAccountName(), urlPath), '?=&', cha + ':' + cha);
    

    And you get back and XML with the information.

    Regards
  • julkifli33julkifli33 Member Posts: 1,092
    Hi @ftornero
    perfect !
    Thank you so much
  • julkifli33julkifli33 Member Posts: 1,092
    edited 2021-10-05
    Hi @ftornero
    are we able to move the file after successfully imported ?
    like for example this TestFile.csv
    once imported then it should be moved to History folder.
    w2ephkdx1wh9.png
  • ftorneroftornero Member Posts: 524
    Hello @julkifli33,

    I haven't seen any method to move a file, so I think that you need delete the imported file and create a new one in the destination folder.

    Regards.
  • julkifli33julkifli33 Member Posts: 1,092
    Hi @ftornero ,
    yeah i managed to solve this issue.
    recreate the file to another folder
    and then delete this file
    thx
Sign In or Register to comment.