Azure Rest API。如何创建文件夹并检查文件夹是否存在?
Azure Rest API. How to create a folder and check whether a folder exists or not?
我想使用 azure blob rest 创建文件夹 api 并且还想检查文件夹是否存在。
Hierarchy:
arjun/images/
arjun/Videos/001.avi
arjun/Vidos/002.avi
img001.jpg
I tried to send a PUT request in order to create a folder with path
for example "arjun/images/"
:
- This creates a folder but its not empty.
- It is creating an empty file with no name inside the folder.
现在,即使这是正确的,另一个问题是当我想检查文件夹是否存在时:
- 我正在发送以前缀作为文件夹路径的列表 blob 调用。
- 现在的问题是区分空文件夹和不存在的文件夹,因为如果请求格式正确,它将始终是
200 Ok message
和 Blob element empty
。
So, can't tell whether a folder doesn't exists or is empty.
i.e. a blob list request with prefix "arjun/xyz/"
and "arjun/images/
both will be successful but will have response body empty as both doesn't
contain any content. But, in reality first folder xyz doesn't exist
and second folder exists but empty.
The Blob service is based on a flat storage scheme, not a hierarchical
scheme.
来源:Blob Names
这清楚地表明 Azure 存储 Blob 实际上 没有文件夹层次结构 ,"folder" 只是用于创建虚拟层次结构的虚拟目录。
此外,如果您尝试使用 Microsoft Storage Explorer 创建虚拟目录,它还会向您强调虚拟目录不存在,直到您将 blob 放入其中,这非常有意义,因为虚拟目录实际上只是 blob 名称的一部分。
总之,如果您 "create" 没有向其中上传任何 blob,则虚拟目录不存在。
正如 David Makogon 和 juvchan 提到的那样,Azure 存储 blob 没有文件夹层次结构。如果"folder"中没有blob,则等同于"folder"不存在。如果 "folder" 中有 blob,那么我们可以从 List blobs API 响应主体中获取列表 blob 计数。所以我们不用担心文件夹不存在或者是空的,都是不存在的意思。
我想使用 azure blob rest 创建文件夹 api 并且还想检查文件夹是否存在。
Hierarchy:
arjun/images/
arjun/Videos/001.avi
arjun/Vidos/002.avi
img001.jpg
I tried to send a PUT request in order to create a folder with path for example
"arjun/images/"
:
- This creates a folder but its not empty.
- It is creating an empty file with no name inside the folder.
现在,即使这是正确的,另一个问题是当我想检查文件夹是否存在时:
- 我正在发送以前缀作为文件夹路径的列表 blob 调用。
- 现在的问题是区分空文件夹和不存在的文件夹,因为如果请求格式正确,它将始终是
200 Ok message
和Blob element empty
。
So, can't tell whether a folder doesn't exists or is empty.
i.e. a blob list request with prefix
"arjun/xyz/"
and"arjun/images/
both will be successful but will have response body empty as both doesn't contain any content. But, in reality first folder xyz doesn't exist and second folder exists but empty.
The Blob service is based on a flat storage scheme, not a hierarchical scheme.
来源:Blob Names
这清楚地表明 Azure 存储 Blob 实际上 没有文件夹层次结构 ,"folder" 只是用于创建虚拟层次结构的虚拟目录。
此外,如果您尝试使用 Microsoft Storage Explorer 创建虚拟目录,它还会向您强调虚拟目录不存在,直到您将 blob 放入其中,这非常有意义,因为虚拟目录实际上只是 blob 名称的一部分。
总之,如果您 "create" 没有向其中上传任何 blob,则虚拟目录不存在。
正如 David Makogon 和 juvchan 提到的那样,Azure 存储 blob 没有文件夹层次结构。如果"folder"中没有blob,则等同于"folder"不存在。如果 "folder" 中有 blob,那么我们可以从 List blobs API 响应主体中获取列表 blob 计数。所以我们不用担心文件夹不存在或者是空的,都是不存在的意思。