none
Write binary or base64 data to Excel file using Sharepoint Update file RRS feed

  • Question

  • (Opened a StackOverflow question https://stackoverflow.com/questions/61863612/sharepoint-update-excel-file-with-base64-content-in-azure-logic-apps with no response)

    I have an Azure Logic App that takes file content, encodes it into base64, and sends it to an Azure Function. Afterwards, the Function returns the manipulated Excel data in base64 format.

    How can I take this new data and write it to a SharePoint file using 'Update file?' I currently am using this method but the output comes out with some of the correct data being scattered amongst jibberish. Same result with decodeBase64 instead of base64ToBinary.

    I know the issue is with writing as opposed to my excel data being corrupted because I copied and pasted the output of my function to x.txt and ran $ base64 -d -i x.txt >> mtestfile.xls which resulted in the output I wanted.

    I now attempted to output my data in a URI like data:application/vnd.ms-excel;base64,<data> and used dataUriToBinary which had the same result. Not sure where to go from here. I tried writing it without decoding to no success.

    Monday, May 18, 2020 7:33 PM

All replies

  • Hi Jack - Are you able to share a screenshot of your Logic Apps workflow? Definitely sounds like an encoding/decoding issue somewhere in one of the components.
    Saturday, May 23, 2020 8:55 PM
    Moderator
  • Sure! Apparently my account is not verified so here is a link to an imgur – https://imgur.com/a/XASPJL7

    {

    "definition": { "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", "actions": { "For_each": { "actions": { "Condition": { "actions": { "Update_file": { "inputs": { "body": "@{decodeBase64(body('tracking-development'))}", "host": { ... }, "method": "put", "path": "..." }, "runAfter": {}, "type": "ApiConnection" } }, "expression": { "and": [ { "equals": [ "@outputs('tracking-development')['statusCode']", 200 ] } ] }, "runAfter": { "tracking-development": [ "Succeeded" ] }, "type": "If" }, "Get_file_content": { "inputs": { "host": { "connection": { "name": "@parameters('$connections')['sharepointonline']['connectionId']" } }, "method": "get", "path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://hedayacapital.sharepoint.com/sites/OperationsTeam'))}/files/@{encodeURIComponent(items('For_each')?['{Identifier}'])}/content", "queries": { "inferContentType": true } }, "runAfter": {}, "type": "ApiConnection" }, "tracking-development": { "inputs": { "body": { "$content": "@{base64(body('Get_file_content'))}", "filename": "@{items('For_each')?['{FilenameWithExtension}']}" }, "function": { "id": "..." } }, "runAfter": { "Get_file_content": [ "Succeeded" ] }, "type": "Function" } }, "foreach": "@triggerBody()?['value']", "runAfter": {}, "type": "Foreach" } }, "contentVersion": "1.0.0.0", "outputs": {}, "parameters": { "$connections": { "defaultValue": {}, "type": "Object" } }, "triggers": { "When_a_file_is_created_in_a_folder": { ... } } }, "parameters": { "$connections": { "value": { "sharepointonline": { ... } } } } }



    Sunday, May 24, 2020 9:42 AM
  • Assuming it's .xlsx format, you need construct the file content object as follows:

    {
        "$content-type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        "$content": "your base 64 goes here"
    }

    If it's .xls then the MIME type is application/vnd.ms-excel
    • Edited by WillPage 3 hours 38 minutes ago
    3 hours 39 minutes ago