简体   繁体   English

从Azure Blob存储中返回Blob但不保存它

[英]Return blob from azure blob storage without saving it

I am trying to get the blob from Azure blob storage and return the files to the user for download. 我正在尝试从Azure blob存储中获取blob,并将文件返回给用户以进行下载。

Now what I am trying to do is to get the file from azure, save it locally, and return the file as using Static file: 现在,我想做的是从azure获取文件,将其保存在本地,然后像使用静态文件一样返回文件:

   def getDownload(filename):
        try:
            file = blob.get_blob('picture', filename)
            with open(filename, 'w') as f:
                f.write(file)
        except:
            abort(400, 'Download blob fail')
        return static_file(filename, root='.', download=filename)

What I am trying to do it to stream it to user without first saving the file in the server. 我正在尝试将其流式传输给用户,而无需先将文件保存在服务器中。

How can I achieve it? 我该如何实现?

Unfortunately I don't have any python sample code, but here is what you can do for verification purposes: 不幸的是,我没有任何python示例代码,但是您可以按照以下步骤进行验证:

  1. Make sure the container is not publicly accessible 确保该容器不可公开访问
  2. Client sends a request to your web application for a given file inside the blob to your web application 客户端向您的Web应用程序发送对Blob中给定文件的请求到您的Web应用程序
  3. Verify if this client is allowed to access that blob (return a 401 error, if not) 验证是否允许此客户端访问该Blob(如果没有,则返回401错误)
  4. Create a Shared Access Signature for this blob for a short timeframe (approx. 5 mins should do) 在较短的时间内为此斑点创建一个共享访问签名(大约需要5分钟)
  5. Return a 303 (see other) html status code to the client containing the url to the blob in the Location-Header 返回303(请参阅其他)html状态代码给客户端,该客户端包含Location-Header中blob的网址

Example: 例:

Client requests http://myservice.cloudapp.net/blobs/somefile.ext and is verified to access the resource. 客户端请求http://myservice.cloudapp.net/blobs/somefile.ext ,并经过验证可以访问资源。 Then he will be redirected to http://mystorage.blob.core.windows.net/container/somefile.ext?SHARED_ACCESS_SIGNATURE . 然后,他将被重定向到http://mystorage.blob.core.windows.net/container/somefile.ext?SHARED_ACCESS_SIGNATURE This link is only available to that client for a few minutes. 该链接仅在几分钟内可供该客户端使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM