azureazure-blob-storageazure-storageazure-logic-appsazure-stream-analytics

How to add to Azure Blob Storage from Logic App


I have an Azure Stream Analytics job which adds JSON data to an Azure storage container as an output. The data is organized in a folder structure based on the date, as specified in the stream analytics output here: ASA Output Details

I also have a Logic App which I want to add data to the same place. I am looking at the logic app Blob Storage actions and cant figure out how to do this. The Update Blob action seems to want to point to a single blob file, rather than having it integrated into the data based on date.

Is there a way to do this with the Logic Apps actions? Or maybe there is a better way to structure my data so that I can add events both from stream analytics as well as from logic apps?

Thanks!


Solution

  • To add blobs to the same folder structure you need to mention the path. To achieve your requirement I have used Create blob action and added blobs to the required folder.

    enter image description here

    In case if you are trying to automate this process to run everyday and add files to everyday to the date path, then try following the below flow.

    enter image description here

    You can reproduce the same in your environment using the below code view

    {
        "definition": {
            "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
            "actions": {
                "Compose": {
                    "inputs": {
                        "Sample": "Sample Json from Logic Apps"
                    },
                    "runAfter": {},
                    "type": "Compose"
                },
                "Create_blob_(V2)": {
                    "inputs": {
                        "body": "@outputs('Compose')",
                        "headers": {
                            "ReadFileMetadataFromServer": true
                        },
                        "host": {
                            "connection": {
                                "name": "@parameters('$connections')['azureblob']['connectionId']"
                            }
                        },
                        "method": "post",
                        "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/files",
                        "queries": {
                            "folderPath": "/container1/@{formatDateTime(utcNow(),'yyyy')}/@{formatDateTime(utcNow(),'MM')}/@{formatDateTime(utcNow(),'dd')}",
                            "name": "LAEvent.json",
                            "queryParametersSingleEncoded": true
                        }
                    },
                    "runAfter": {
                        "Compose": [
                            "Succeeded"
                        ]
                    },
                    "runtimeConfiguration": {
                        "contentTransfer": {
                            "transferMode": "Chunked"
                        }
                    },
                    "type": "ApiConnection"
                }
            },
            "contentVersion": "1.0.0.0",
            "outputs": {},
            "parameters": {
                "$connections": {
                    "defaultValue": {},
                    "type": "Object"
                }
            },
            "triggers": {
                "manual": {
                    "inputs": {
                        "schema": {}
                    },
                    "kind": "Http",
                    "type": "Request"
                }
            }
        },
        "parameters": {
            "$connections": {
                "value": {
                    "azureblob": {
                        "connectionId": "/subscriptions/<SUB_ID>/resourceGroups/<RG>/providers/Microsoft.Web/connections/azureblob",
                        "connectionName": "azureblob",
                        "id": "/subscriptions/<SUB_ID>/providers/Microsoft.Web/locations/centralus/managedApis/azureblob"
                    }
                }
            }
        }
    }
    

    In Storage account:

    enter image description here


    Updated Answer

    In the case where you want to add data to an existing blob, you can concat both the data which is already present in the blob and the new logic app's data using concat function.

    concat(body('Get_blob_content_(V2)'),outputs('Compose'))
    

    enter image description here

    RESULTS:

    enter image description here