ved*_*eda 80 c# directory azure azure-blob-storage
如何在blob容器中创建子目录
例如,
在我的blob容器中http://veda.blob.core.windows.net/document/
如果我存储一些文件,它将是
现在,如何创建子目录
这样我就可以存储文件了
use*_*559 119
要添加到Egon所说的内容,只需创建名为"folder/1.txt"的blob,它就能正常工作.无需创建目录.
Ego*_*gon 32
实际上只有一层容器.您可以虚拟地创建一个像分层存储一样的"文件系统",但实际上一切都将在1层,即容器中.
要创建像存储一样的虚拟"文件系统",您可以使用包含"/"的blob名称,以便您可以按照存储方式执行任何操作.此外,最棒的是你可以通过提供一个部分字符串来搜索虚拟级别的blob,最多为'/'.
这两件事,在路径中添加'/'和搜索的部分字符串,共同创建了一个虚拟的"文件系统"存储.
Ant*_*onB 31
@ afr0有一个评论询问如何过滤文件夹..
有两种方法可以使用GetDirectoryReference或循环遍历容器blob并检查类型.下面的代码在C#中
CloudBlobContainer container = blobClient.GetContainerReference("photos");
//Method 1. grab a folder reference directly from the container
CloudBlobDirectory folder = container.GetDirectoryReference("directoryName");
//Method 2. Loop over container and grab folders.
foreach (IListBlobItem item in container.ListBlobs(null, false))
{
if (item.GetType() == typeof(CloudBlobDirectory))
{
// we know this is a sub directory now
CloudBlobDirectory subFolder = (CloudBlobDirectory)item;
Console.WriteLine("Directory: {0}", subFolder.Uri);
}
}
Run Code Online (Sandbox Code Playgroud)
阅读本文以获得更多深度报道:http://www.codeproject.com/Articles/297052/Azure-Storage-Blobs-Service-Working-with-Directori
您不需要创建子目录。只需创建 blob 容器并使用文件名,如变量文件名,如下代码:
string filename = "document/tech/user-guide.pdf";
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(ConnectionString);
CloudBlockBlob blob = cloudBlobContainer.GetBlockBlobReference(filename);
blob.StreamWriteSizeInBytes = 20 * 1024;
blob.UploadFromStream(fileStream); // fileStream is System.IO.Stream
Run Code Online (Sandbox Code Playgroud)
小智 5
对于那些在动态目录中苦苦挣扎的人
根据版本 12
<PackageReference Include="Azure.Storage.Blobs" Version="12.10.0"/>
Run Code Online (Sandbox Code Playgroud)
您可以轻松地用反斜杠分隔目录或文件夹路径。在这种情况下,它们将自动创建。例子:
public async Task UploadFile(string env, string filePath, string filename, Guid companyId, Guid assetId, string baseKey)
{
var blobContainer = blobServiceClient.GetBlobContainerClient("graphs-data");
if (!blobContainer.Exists())
{
blobContainer.Create();
}
var blobClient = blobContainer.GetBlobClient($"input/{env}/{companyId}/iotasset/{assetId}/{baseKey}/{filename}");
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
await blobClient.UploadAsync(fs, overwrite: true);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
80478 次 |
| 最近记录: |