Skip to content

[Bug]: ABS Operation fails when blob contains # in file name #1088

@ptrk-tr

Description

@ptrk-tr

Describe the issue

I'll describe this issue based on the GetBlobAsStream procedure of the ABS Blob Client Codeunit as I haven't tested with other operations yet.

The blob name isn't escaped in the operation so the response returns a 404. In case the ABS Operation Response return parameter isn't used and instead only the InStream is used further in the code, the InStream contains 215 Bytes of data.

GetBlobAsStream calls the SetBlobName(BlobName) procedure of the "ABS Operation Payload" codeunit which in turn just assigns the parameter to its global variable "BlobName". In the procedure PrepareRequestMsg of the "ABS Web Request Helper" Codeunit the Request Uri is set via the ConstructUri procedure of the "ABS Operation Payload" Codeunit, which calls the ConstructUri procedure in the "ABS URI Helper" Codeunit.

ConstructUri in the URI Helper codeunit calls a procedure called "AppendBlobIfNecessary" that does.. just that:

if not ConstructedUrl.EndsWith('/') then
            ConstructedUrl += '/';
        ConstructedUrl += BlobName;

If the file name of the blob contains a # this won't get escaped which leads to the HttpClient.Send() request not finding the specified blob. I assume in itself not escaping the # is correct, as it's used to jump to anchor points in a website, but I don't see those being applicable in a storage container.

I could provide a fix for this, as the easiest solution in my opinion would be to either call EscapeDataString() from the Uri Codeunit when SetBlobName() is called, or when the Blob name is appended in AppendBlobIfNecessary. This also doesn't hurt when other special characters are present in the file name (tested with !$# characters, when escaping them, the blob is still found, to be tested if that works with other operation types as well).

Appreciate any opinions on how to best fix this.

Expected behavior

The # in the blob name gets escaped properly when the request uri is constructed.

Steps to reproduce

  • create a storage account
  • create a container
  • upload a file containing a # in the file name
  • use the GetBlobAsStream() procedure in the "ABS Blob Client" to read this blob into an InStream
  • look at the error message in the "ABS Operation Response" Codeunit, which should show a 404 in this case

code snippet to reproduce:

action(ABSOperation)
{
    Caption = 'ABS Operation';
    ToolTip = 'Tries to get a blob with the special character # in the file name from Azure Blob Storage.';
    ApplicationArea = All;
    Image = TestFile;
    trigger OnAction()
    var
        ABSClient: Codeunit "ABS Blob Client";
        ABSStorageAuth: Codeunit "Storage Service Authorization";
        ABSOperationResponse: Codeunit "ABS Operation Response";
        IABSServiceAuth: Interface "Storage Service Authorization";
        InStr: InStream;
    begin
        IABSServiceAuth := ABSStorageAuth.CreateSharedKey('<insertSharedKey>');
        ABSClient.Initialize('<insertStorageAccountName>', '<insertContainerName>', IABSServiceAuth);
        ABSOperationResponse := ABSClient.GetBlobAsStream('<insertFile#Name.pdf>', InStr);
        if not ABSOperationResponse.IsSuccessful() then
            Message(ABSOperationResponse.GetError());
    end;
}

Additional context

No response

I will provide a fix for a bug

  • I will provide a fix for a bug

Metadata

Metadata

Assignees

Labels

ApprovedThe issue is approvedBugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions