gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:00:41 24 4
gpt4 key购买 nike

在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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com