【问题标题】:How to get the filepath while uploading a file to azure-storage in django如何在将文件上传到 django 中的 azure-storage 时获取文件路径
【发布时间】:2019-05-02 17:33:04
【问题描述】:

我有一个可以上传文件的表单。上传的文件必须存储在 azure-storage 中。我正在使用 create_blob_from_path 将文件上传到 azure-storage.create_blob_from_path 期望文件路径作为参数之一。但是在这种情况下如何获取文件路径,因为操作必须处于动态模式(上传的文件不能存储在任何本地存储中)。它应该直接存储在 Azure 中。

if request.method=="POST":
    pic=request.FILES['pic']
    block_blob_service = BlockBlobService(account_name='samplestorage', account_key='5G+riEzTzLmm3MR832NEVjgYxaBKA4yur6Ob+A6s5Qrw==')
    container_name ='quickstart'
    block_blob_service.create_container(container_name)        
    block_blob_service.set_container_acl(container_name, public_access=PublicAccess.Container)
    block_blob_service.create_blob_from_path(container_name, pic, full_path_to_file)//full_path_to_file=?

动态上传的文件必须存储在 Azure 中

【问题讨论】:

  • 在你的情况下,你应该使用 block_blob_service.create_blob_from_stream 或 block_blob_service.create_blob_from_text,它不需要文件路径。

标签: django azure azure-storage


【解决方案1】:

如果上传的文件不能存储在任何本地存储中,可以将文件内容读取为流或文本(字符串),然后分别使用create_blob_from_streamcreate_blob_from_text方法。

【讨论】:

    猜你喜欢
    • 2017-02-20
    • 1970-01-01
    • 2016-01-14
    • 2022-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-21
    • 2018-12-11
    相关资源
    最近更新 更多