azure - 使用 Azure 逻辑应用列出和查看 Azure 存储容器的内容?

标签 azure azure-blob-storage storage

在Azure中,将为Azure存储中的每个用户创建一个容器,我希望能够列出容器并查看内容的大小以确保它不超过一定的限制。是否可以使用 Azure 逻辑应用来执行此操作?我没有找到这样做的函数。

最佳答案

是的,这可以通过逻辑应用程序实现。您可以使用“获取 Blob 元数据 (V2)”来获取文件的所有属性,如果您尝试获取内容,则可以使用“获取 Blob 内容 (V2)”。为了重现这一点,我首先创建了 3 个容器(即 Container1、Container2 和 Container3),并将一些不同大小的文件上传到这些容器中。为了获取所有容器的列表,我使用了 Lists blobs in the root folder (V2) 并使用 Lists blobs (V2) 获取上一步中的路径进行迭代容器内的 Blob 。

enter image description here

在下一步中,我将使用获取 Blob 元数据 (V2) 通过列出 Blob 路径来获取每个 Blob 的属性。

enter image description here

然后使用 Condition 操作提取小于 9128 字节的 blob 并将所有这些数据存储到变量中。

enter image description here

最后,我使用 compose 连接器来查看所有文件以及大小和路径。

enter image description here

结果:

enter image description here

enter image description here

enter image description here

您可以尝试使用下面的代码 View 在您的环境中进行测试

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": "@variables('FilesWithinLimit')",
                "runAfter": {
                    "For_each": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "Compose_2": {
                "inputs": "@variables('FilesOutOfLimit')",
                "runAfter": {
                    "For_each": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "FilesOutOfLimit": {
                "inputs": {
                    "variables": [
                        {
                            "name": "FilesOutOfLimit",
                            "type": "array"
                        }
                    ]
                },
                "runAfter": {
                    "FilesWithinLimit": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "FilesWithinLimit": {
                "inputs": {
                    "variables": [
                        {
                            "name": "FilesWithinLimit",
                            "type": "array"
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            },
            "For_each": {
                "actions": {
                    "For_each_2": {
                        "actions": {
                            "Condition": {
                                "actions": {
                                    "Append_to_FilesWithinLimit": {
                                        "inputs": {
                                            "name": "FilesWithinLimit",
                                            "value": {
                                                "Name": "@{body('Get_Blob_Metadata_(V2)')?['DisplayName']}",
                                                "Path": "@{body('Get_Blob_Metadata_(V2)')?['Path']}",
                                                "Size": "@{body('Get_Blob_Metadata_(V2)')?['Size']}"
                                            }
                                        },
                                        "runAfter": {},
                                        "type": "AppendToArrayVariable"
                                    }
                                },
                                "else": {
                                    "actions": {
                                        "Append_to_FilesOutOfLimit": {
                                            "inputs": {
                                                "name": "FilesOutOfLimit",
                                                "value": {
                                                    "Name": "@{body('Get_Blob_Metadata_(V2)')?['DisplayName']}",
                                                    "Path": "@{body('Get_Blob_Metadata_(V2)')?['Path']}",
                                                    "Size": "@{body('Get_Blob_Metadata_(V2)')?['Size']}"
                                                }
                                            },
                                            "runAfter": {},
                                            "type": "AppendToArrayVariable"
                                        }
                                    }
                                },
                                "expression": {
                                    "and": [
                                        {
                                            "lessOrEquals": [
                                                "@body('Get_Blob_Metadata_(V2)')?['Size']",
                                                9128
                                            ]
                                        }
                                    ]
                                },
                                "runAfter": {
                                    "Get_Blob_Metadata_(V2)": [
                                        "Succeeded"
                                    ]
                                },
                                "type": "If"
                            },
                            "Get_Blob_Metadata_(V2)": {
                                "inputs": {
                                    "host": {
                                        "connection": {
                                            "name": "@parameters('$connections')['azureblob']['connectionId']"
                                        }
                                    },
                                    "method": "get",
                                    "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/files/@{encodeURIComponent(encodeURIComponent(items('For_each_2')?['Path']))}"
                                },
                                "runAfter": {},
                                "type": "ApiConnection"
                            }
                        },
                        "foreach": "@body('Lists_blobs_(V2)')?['value']",
                        "runAfter": {
                            "Lists_blobs_(V2)": [
                                "Succeeded"
                            ]
                        },
                        "type": "Foreach"
                    },
                    "Lists_blobs_(V2)": {
                        "inputs": {
                            "host": {
                                "connection": {
                                    "name": "@parameters('$connections')['azureblob']['connectionId']"
                                }
                            },
                            "method": "get",
                            "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/foldersV2/@{encodeURIComponent(encodeURIComponent(items('For_each')?['Path']))}",
                            "queries": {
                                "nextPageMarker": ""
                            }
                        },
                        "runAfter": {},
                        "type": "ApiConnection"
                    }
                },
                "foreach": "@body('Lists_blobs_in_the_root_folder__(V2)')?['value']",
                "runAfter": {
                    "Lists_blobs_in_the_root_folder__(V2)": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Lists_blobs_in_the_root_folder__(V2)": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureblob']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/foldersV2",
                    "queries": {
                        "nextPageMarker": "",
                        "useFlatListing": false
                    }
                },
                "runAfter": {
                    "FilesOutOfLimit": [
                        "Succeeded"
                    ]
                },
                "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/<Your_SUBSCRIPTION_ID>/resourceGroups/<YOUR_RESOURCE_GROUP>/providers/Microsoft.Web/connections/azureblob",
                    "connectionName": "azureblob",
                    "id": "/subscriptions/<Your_SUBSCRIPTION_ID>/providers/Microsoft.Web/locations/centralus/managedApis/azureblob"
                }
            }
        }
    }
}

关于azure - 使用 Azure 逻辑应用列出和查看 Azure 存储容器的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72418671/

相关文章:

azure - 使用 blob 存储配置和监视 log4net

wcf - 在 Windows Azure 中部署时拒绝访问 URL?

c# - 在 Azure Functions 上使用 AdWords API

azure - Azure 的 "Data Lake Storage Gen2"和 "Data Lake Gen2"之间有什么区别?

flask - 下载文件而不存储它

asp.net-mvc - 当托管在 Azure 网站中时,除了 App_Data 之外,asp MVC 网站中的哪个文件夹可以访问来存储和检索文件?

c# - 获取容器中 Azure blob 文件的名称列表?

java - Azure函数无法找到具有给定输入的方法签名

objective-c - 如何以编程方式获取mac的存储容量?

java - Android 存储 - 即使设置了权限,也无法读取应用程序目录之外的目录文件