自动从Azure存储中解压缩密码保护的Zip文件吗?

用户14780013

我只是想知道是否有一种方法可以从Azure存储中提取受密码保护的zip文件。我尝试使用python Azure函数无济于事,但在读取文件位置时遇到了问题。

该文件是否必须暂时存储在共享位置上才能实现?

只是在这里寻找方向,我是否错过了一步?

问候,詹姆斯

斯坦利·龚

Azure blob存储仅提供存储功能,没有正在运行的env可以执行解压缩操作。因此,基本上,我们应该将.zip文件下载到Azure函数,将其解压缩,然后按1上载到.zip文件中的文件。

为了进行快速测试,我编写了一个HTTP触发器Azure功能演示,该示例演示了使用密码保护的zip文件解压缩,它在local上对我有用:

import azure.functions as func
import uuid
import os
import shutil
from azure.storage.blob import ContainerClient
from zipfile import ZipFile

storageAccountConnstr = '<storage account conn str>'
container = '<container name>'

#define local temp path, on Azure, the path is recommanded under /home 
tempPathRoot = 'd:/temp/'
unZipTempPathRoot = 'd:/unZipTemp/'


def main(req=func.HttpRequest) -> func.HttpResponse:
    reqBody = req.get_json()
    fileName = reqBody['fileName']
    zipPass =  reqBody['password']

    container_client = ContainerClient.from_connection_string(storageAccountConnstr,container)

    #download zip file 
    zipFilePath = tempPathRoot + fileName
    with open(zipFilePath, "wb") as my_blob:
       download_stream = container_client.get_blob_client(fileName).download_blob()
       my_blob.write(download_stream.readall())

    #unzip to temp folder
    unZipTempPath = unZipTempPathRoot + str(uuid.uuid4())
    with ZipFile(zipFilePath) as zf:
        zf.extractall(path=unZipTempPath,pwd=bytes(zipPass,'utf8'))

    #upload all files in temp folder
    for root, dirs, files in os.walk(unZipTempPath):
        for file in files: 
            filePath = os.path.join(root, file)
            destBlobClient = container_client.get_blob_client(fileName + filePath.replace(unZipTempPath,''))
            with open(filePath, "rb") as data:
                destBlobClient.upload_blob(data,overwrite=True)
    
    #remove all temp files 
    shutil.rmtree(unZipTempPath)
    os.remove(zipFilePath)

    return func.HttpResponse("done")

我的容器中的文件: 在此处输入图片说明

结果: 在此处输入图片说明 在此处输入图片说明 在此处输入图片说明

使用blob触发器会更好,因为如果zip文件的大小很大,则会导致超时错误。

无论如何,这只是一个演示,向您展示如何执行此操作。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在vbsript中解压缩受密码保护的文件

来自分类Dev

在R中解压缩受密码保护的zip文件

来自分类Dev

如何使用终端解压缩受密码保护的.zip文件?

来自分类Dev

如何使用 Java 解压缩目录中所有受密码保护的 zip 文件

来自分类Dev

解压缩Node.js中受密码保护的文件

来自分类Dev

受密码保护的.zip解压缩到空文件夹(不提示输入密码)

来自分类Dev

为什么python无法使用zip方法解压缩winrar创建的受密码保护的zip文件?

来自分类Dev

解压缩受密码保护的文件时出现权限错误

来自分类Dev

如何在不使用其他zip工具的情况下使批处理脚本解压缩受密码保护的.zip文件?

来自分类Dev

如何提取使用Python中的PKWARE SecureZip压缩的受密码保护的zip文件?(Windows 10)

来自分类Dev

在Powershell中替换* .zip文件中的文件而无需解压缩(解压缩)

来自分类Dev

在Linux中从.zip文件解压缩text / csv文件

来自分类Dev

从多个zip文件中解压缩特定文件

来自分类Dev

如何在Microsoft Azure Logic App中解压缩.zip文件?

来自分类Dev

在Azure自动化中解压缩.7z文件

来自分类Dev

从内存中的FTP下载Zip文件并解压缩

来自分类Dev

在Java中无需解压缩即可替换Zip文件

来自分类Dev

解压缩存储在Azure ADLS Gen2中的.Z文件

来自分类Dev

使用Swift解压缩zip文件

来自分类Dev

如何“解压缩” zip文件?

来自分类Dev

如何解压缩“ .zip”文件?

来自分类Dev

如何从终端解压缩zip文件?

来自分类Dev

.zip文件未解压缩

来自分类Dev

解压缩前访问zip文件

来自分类Dev

无法解压缩zip文件

来自分类Dev

检查Zip文件的内容并解压缩

来自分类Dev

Windows:解压缩非.zip文件

来自分类Dev

密码保护自动生成的.html文件

来自分类Dev

在Azure数据工厂中解压缩gzip文件

Related 相关文章

  1. 1

    在vbsript中解压缩受密码保护的文件

  2. 2

    在R中解压缩受密码保护的zip文件

  3. 3

    如何使用终端解压缩受密码保护的.zip文件?

  4. 4

    如何使用 Java 解压缩目录中所有受密码保护的 zip 文件

  5. 5

    解压缩Node.js中受密码保护的文件

  6. 6

    受密码保护的.zip解压缩到空文件夹(不提示输入密码)

  7. 7

    为什么python无法使用zip方法解压缩winrar创建的受密码保护的zip文件?

  8. 8

    解压缩受密码保护的文件时出现权限错误

  9. 9

    如何在不使用其他zip工具的情况下使批处理脚本解压缩受密码保护的.zip文件?

  10. 10

    如何提取使用Python中的PKWARE SecureZip压缩的受密码保护的zip文件?(Windows 10)

  11. 11

    在Powershell中替换* .zip文件中的文件而无需解压缩(解压缩)

  12. 12

    在Linux中从.zip文件解压缩text / csv文件

  13. 13

    从多个zip文件中解压缩特定文件

  14. 14

    如何在Microsoft Azure Logic App中解压缩.zip文件?

  15. 15

    在Azure自动化中解压缩.7z文件

  16. 16

    从内存中的FTP下载Zip文件并解压缩

  17. 17

    在Java中无需解压缩即可替换Zip文件

  18. 18

    解压缩存储在Azure ADLS Gen2中的.Z文件

  19. 19

    使用Swift解压缩zip文件

  20. 20

    如何“解压缩” zip文件?

  21. 21

    如何解压缩“ .zip”文件?

  22. 22

    如何从终端解压缩zip文件?

  23. 23

    .zip文件未解压缩

  24. 24

    解压缩前访问zip文件

  25. 25

    无法解压缩zip文件

  26. 26

    检查Zip文件的内容并解压缩

  27. 27

    Windows:解压缩非.zip文件

  28. 28

    密码保护自动生成的.html文件

  29. 29

    在Azure数据工厂中解压缩gzip文件

热门标签

归档