skip to Main Content

I have multiple text files; I need to append one to the other. I can’t seem to get this to happen; maybe I am doing something wrong.

enter image description here

It’s not appending, its just returning the last text file

2

Answers


  1. I am able to append multiple text files to a text file blob by following the below workflow-

    Workflow

    enter image description here

    enter image description here
    enter image description here
    enter image description here
    enter image description here

    Code

    {
        "definition": {
            "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
            "actions": {
                "Create_blob_(V2)": {
                    "inputs": {
                        "body": " ",
                        "headers": {
                            "ReadFileMetadataFromServer": true
                        },
                        "host": {
                            "connection": {
                                "name": "@parameters('$connections')['azureblob']['connectionId']"
                            }
                        },
                        "method": "post",
                        "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/files",
                        "queries": {
                            "folderPath": "/demo",
                            "name": "FinalTextFile.txt",
                            "queryParametersSingleEncoded": true
                        }
                    },
                    "runAfter": {
                        "Lists_blobs_(V2)": [
                            "Succeeded"
                        ]
                    },
                    "runtimeConfiguration": {
                        "contentTransfer": {
                            "transferMode": "Chunked"
                        }
                    },
                    "type": "ApiConnection"
                },
                "For_each": {
                    "actions": {
                        "Append_to_string_variable": {
                            "inputs": {
                                "name": "FinalData",
                                "value": "@body('Get_blob_content_(V2)')"
                            },
                            "runAfter": {
                                "Get_blob_content_(V2)": [
                                    "Succeeded"
                                ]
                            },
                            "type": "AppendToStringVariable"
                        },
                        "Get_blob_content_(V2)": {
                            "inputs": {
                                "host": {
                                    "connection": {
                                        "name": "@parameters('$connections')['azureblob']['connectionId']"
                                    }
                                },
                                "method": "get",
                                "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/files/@{encodeURIComponent(encodeURIComponent(items('For_each')?['Path']))}/content",
                                "queries": {
                                    "inferContentType": true
                                }
                            },
                            "runAfter": {},
                            "type": "ApiConnection"
                        }
                    },
                    "foreach": "@body('Lists_blobs_(V2)')?['value']",
                    "runAfter": {
                        "Create_blob_(V2)": [
                            "Succeeded"
                        ]
                    },
                    "type": "Foreach"
                },
                "Initialize_variable": {
                    "inputs": {
                        "variables": [
                            {
                                "name": "FinalData",
                                "type": "string"
                            }
                        ]
                    },
                    "runAfter": {},
                    "type": "InitializeVariable"
                },
                "Lists_blobs_(V2)": {
                    "inputs": {
                        "host": {
                            "connection": {
                                "name": "@parameters('$connections')['azureblob']['connectionId']"
                            }
                        },
                        "method": "get",
                        "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/foldersV2/@{encodeURIComponent(encodeURIComponent('J=='))}",
                        "queries": {
                            "nextPageMarker": "",
                            "useFlatListing": false
                        }
                    },
                    "metadata": {
                        "J==": "/demo"
                    },
                    "runAfter": {
                        "Initialize_variable": [
                            "Succeeded"
                        ]
                    },
                    "type": "ApiConnection"
                },
                "Update_blob_(V2)": {
                    "inputs": {
                        "body": " @{variables('FinalData')}",
                        "headers": {
                            "ReadFileMetadataFromServer": true
                        },
                        "host": {
                            "connection": {
                                "name": "@parameters('$connections')['azureblob']['connectionId']"
                            }
                        },
                        "method": "put",
                        "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/files/@{encodeURIComponent(encodeURIComponent(body('Create_blob_(V2)')?['Path']))}"
                    },
                    "runAfter": {
                        "For_each": [
                            "Succeeded"
                        ]
                    },
                    "type": "ApiConnection"
                }
            },
            "contentVersion": "1.0.0.0",
            "outputs": {},
            "parameters": {
                "$connections": {
                    "defaultValue": {},
                    "type": "Object"
                }
            },
            "triggers": {
                "manual": {
                    "inputs": {},
                    "kind": "Http",
                    "type": "Request"
                }
            }
        },
        "parameters": {
            "$connections": {
                "value": {
                    "azureblob": {
                        "connectionId": "/subscriptions/********/resourceGroups/****/providers/Microsoft.Web/connections/azureblob",
                        "connectionName": "azureblob",
                        "id": "/subscriptions/*********/providers/Microsoft.Web/locations/eastus/managedApis/azureblob"
                    }
                }
            }
        }
    }
    

    Output

    enter image description here

    You can also use Append to Array Variable action.

    Login or Signup to reply.
  2. Set Variable will always overwrite the entire variable, so ending with the latest blob is expected behavior.

    As already answered, use the Append To actions to get what you need. If you need to maintain the order of the text files, you can set the For each loop to run sequential by going to Settings -> Concurrency Control to Off -> Set Degree of Parallelism to 1

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search