问题描述
在Django(Python)项目中,我正在使用Azure Blob存储用户上传的照片.代码只是这样:
In a Django (Python) project, I'm using Azure blobs to store photos uploaded by users. The code simply goes something like this:
from azure.storage.blob import BlobService
blob_service = BlobService(account_name=accountName, account_key=accountKey)
blob_service.put_blob(
'pictures',
name, # including folder
content_str, # image as stream
x_ms_blob_type='BlockBlob',
x_ms_blob_content_type=content_type,
x_ms_blob_cache_control ='public, max-age=3600, s-maxage=86400'
)
我的问题是:在我的特定情况下,删除
照片的等效方法是什么?我正在编写一个任务,以定期清理我的数据模型,因此也希望摆脱与它们相关的图像.
My question is: what's the equivalent method to delete
an uploaded photo in my particular scenario? I'm writing a task to periodically clean up my data models, and so want to get rid of images associated to them as well.
推荐答案
您应该可以使用:
blob_service.delete_blob(container_name, blob_name)
您还可以删除整个容器:
You can also delete an entire container:
blob_service.delete_container(container_name)
还有一些额外的参数,如果您要删除快照,处理租约等,将对您有所帮助.
There are a few extra parameters which will be helpful to you if you're trying to delete snapshots, deal with leases, etc.
请注意,在put_blob().py"rel =" nofollow noreferrer> blockblobservice.py ,而 delete_blob()
在 baseblobservice.py (删除内容将是相同的,无论是页面,块还是附加blob).
Note that put_blob()
is defined in blockblobservice.py, while delete_blob()
is defined in baseblobservice.py (deletes are going to be the same, whether page, block, or append blob).
这篇关于有选择地删除上传到Azure blob的图像(Django/Python项目)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!