azure-logic-appsazure-logic-app-standard

Copy Folder along with files from Azure Blob to SharePoint


We have a Blob container - Dev. There are multiple sub folders inside

Dev/6c4999ceb9964e0bb08f30790bd9a673/Upload/NativeFiles/

Inside native file there are multiple folders with files.

I have to copy all the folders along with files to Sharepoint that are inside Nativefiles.

Any suggestions to build this using Logic app workflow

enter image description here


Solution

  • You can use the below workflow to copy folder along with the files from Blob storage to SharePoint.

    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": {
                "Compose": {
                    "inputs": "@substring(body('Lists_blobs_(V2)')?['value'][0]?['Path'],0,lastIndexOf(body('Lists_blobs_(V2)')?['value'][0]?['Path'],'/'))",
                    "runAfter": {
                        "Lists_blobs_(V2)": [
                            "SUCCEEDED"
                        ]
                    },
                    "type": "Compose"
                },
                "Create_new_folder": {
                    "inputs": {
                        "body": {
                            "path": "@{outputs('Compose')}"
                        },
                        "host": {
                            "connection": {
                                "referenceName": "sharepointonline"
                            }
                        },
                        "method": "post",
                        "path": "/datasets/@{encodeURIComponent(encodeURIComponent('*******'))}/tables/@{encodeURIComponent(encodeURIComponent('e2b0ea6'))}/createnewfolder"
                    },
                    "runAfter": {
                        "Compose": [
                            "SUCCEEDED"
                        ]
                    },
                    "type": "ApiConnection"
                },
                "For_each": {
                    "actions": {
                        "Create_file": {
                            "inputs": {
                                "body": "@body('Get_blob_content_using_path_(V2)')",
                                "host": {
                                    "connection": {
                                        "referenceName": "sharepointonline"
                                    }
                                },
                                "method": "post",
                                "path": "/datasets/@{encodeURIComponent(encodeURIComponent('********'))}/files",
                                "queries": {
                                    "folderPath": "@body('Create_new_folder')?['{FullPath}']",
                                    "name": "@item()?['DisplayName']",
                                    "queryParametersSingleEncoded": true
                                }
                            },
                            "runAfter": {
                                "Get_blob_content_using_path_(V2)": [
                                    "SUCCEEDED"
                                ]
                            },
                            "runtimeConfiguration": {
                                "contentTransfer": {
                                    "transferMode": "Chunked"
                                }
                            },
                            "type": "ApiConnection"
                        },
                        "Get_blob_content_using_path_(V2)": {
                            "inputs": {
                                "host": {
                                    "connection": {
                                        "referenceName": "azureblob"
                                    }
                                },
                                "method": "get",
                                "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/GetFileContentByPath",
                                "queries": {
                                    "inferContentType": true,
                                    "path": "@items('For_each')?['Path']",
                                    "queryParametersSingleEncoded": true
                                }
                            },
                            "type": "ApiConnection"
                        }
                    },
                    "foreach": "@body('Lists_blobs_(V2)')?['value']",
                    "runAfter": {
                        "Create_new_folder": [
                            "SUCCEEDED"
                        ]
                    },
                    "type": "foreach"
                },
                "Lists_blobs_(V2)": {
                    "inputs": {
                        "host": {
                            "connection": {
                                "referenceName": "azureblob"
                            }
                        },
                        "method": "get",
                        "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/foldersV2/@{encodeURIComponent(encodeURIComponent('JTJ********='))}",
                        "queries": {
                            "nextPageMarker": "",
                            "useFlatListing": true
                        }
                    },
                    "metadata": {
                        "JTJmZGV2": "/dev",
                        "JTJ********g==": "/dev/6c4999ceb93/Upload/NativeFiles/"
                    },
                    "runAfter": {},
                    "type": "ApiConnection"
                }
            },
            "contentVersion": "1.0.0.0",
            "outputs": {},
            "triggers": {
                "When_a_HTTP_request_is_received": {
                    "kind": "Http",
                    "type": "Request"
                }
            }
        },
        "kind": "Stateful"
    }
    

    Files in Storage Account-

    enter image description here

    Output-

    enter image description here

    enter image description here