Blog Post

Azure Integration Services Blog
1 MIN READ

Logic app creates unreadable base64 encoded files using HTTP action on Azure Blob Storage

talsaifi's avatar
talsaifi
Icon for Microsoft rankMicrosoft
Dec 21, 2020

When the logic app creates a file using HTTP action PUT method on Azure Blob Storage, the file cannot be read as it appears as corrupted when trying to open the file.

 

The main reason for this is that in order to avoid problems with special characters, Logic app uses Base64 encoding to encode files while processing, as a result the created files are Base64 encoded and in order for the files to be created correctly to Azure Blob Storage, it needs to be converted to binary.

 

For example, the following line of text:
Test 1234 as Base64!
would instead appear as:
VGVzdCAxMjM0IGFzIEJhc2U2NCE

 

To resolve this, use base64toBinary() function when creating files on Azure Blob Storage, so we apply this function to the file content passed in the body field of the HTTP action.

 

You will need to switch to code view to apply this function manually, final HTTP body should look like the following:

 

"body": "@{base64ToBinary(items('For_each')?['ContentBytes'])}",
Updated Dec 21, 2020
Version 1.0
  • c-sekhar's avatar
    c-sekhar
    Copper Contributor

    I'm using base64ToBinary while using the CreateBlob v2 - in the body. I also specify the Content Type as well to indicate its an Excel FIle. 

    When I create the file and view the file content, the content matches exactly to the content when I manually upload in the portal - into the same container. But the file size is different - the CreateBlob shows a significantly larger file size. And when I download the files - the one directly uploaded through portal opens just fine in Excel but the one uploaded through CreateBlob doesn't. 

    When I compare the metadata, I see that the CreateBlob file has the metadata attributes that of a ZIP file and not a EXCEL file. But the file that I uploaded manually in the portal has the metadata which represents a Excel file. 

    Can someone please help?