问题描述
如果我在文件已经存在的同一容器中的天蓝色blob上上传文件,它正在覆盖文件,如何避免覆盖相同文件?下面我要提到的情况...
if i upload a file on azure blob in the same container where the file is existing already, it is over-writing the file, how to avoid overwriting the same? below i am mentioning the scenario...
第1步-将天蓝色的文件"abc.jpg"上传到名为"filecontainer"的容器中
step1 - upload file "abc.jpg" on azure in container called say "filecontainer"
第2步-上传后,尝试将一些具有相同名称的不同文件上传到同一容器中
step2 - once it gets uploaded, try uploading some different file with the same name to the same container
输出-它将使用最新上传的文件覆盖现有文件
Output - it will overwrite existing file with the latest uploaded
我的要求-我想避免这种覆盖,因为不同的人可能会将具有相同名称的文件上传到我的容器中.
My Requirement - i want to avoid this overwrite, as different people may upload files having same name to my container.
请帮助
P.S.
-我不想为不同的用户创建不同的容器
-i do not want to create different containers for different users
-我正在将REST API与Java一起使用
-i am using REST API with Java
推荐答案
Windows Azure Blob存储支持条件标头,使用该标头可以防止Blob覆盖.您可以在此处阅读有关条件标题的更多信息: http://msdn.microsoft. com/en-us/library/windowsazure/dd179371.aspx .
Windows Azure Blob Storage supports conditional headers using which you can prevent overwriting of blobs. You can read more about conditional headers here: http://msdn.microsoft.com/en-us/library/windowsazure/dd179371.aspx.
由于希望不要覆盖Blob,因此需要指定If-None-Match
条件标头并将其值设置为*
.这将导致上传操作失败,并显示Precondition Failed (412)
错误.
Since you want that a blob should not be overwritten, you would need to specify If-None-Match
conditional header and set it's value to *
. This would cause the upload operation to fail with Precondition Failed (412)
error.
其他想法是在上传之前检查blob的存在(通过获取其属性),但是我不推荐这种方法,因为它可能会导致一些并发问题.
Other idea would be to check for blob's existence just before uploading (by fetching it's properties) however I would not recommend this approach as it may lead to some concurrency issues.
这篇关于避免覆盖Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!