Azure Blob存储仅使用文件名,而不使用整个路径

时间:2019-01-07 16:31:49

标签: azure azure-storage-blobs

这完全可以正常工作。它使用整个文件路径将blob保存在Azure中。但是,我只希望将文件名直接保存到“容器”中(而不是整个层次结构)。有什么好方法吗?

        string[] returnedPaths = Open_File_Dialog();

        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

        // Create the blob client.
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

        // container
        CloudBlobContainer container = blobClient.GetContainerReference(_jobID);
        container.CreateIfNotExists();

        foreach (var filePath in returnedPaths)
        {
            CloudBlockBlob blob = container.GetBlockBlobReference(filePath);
            blob.UploadFromFile(filePath);
        }

1 个答案:

答案 0 :(得分:1)

这就是所有需要的东西。

foreach (var filePath in returnedPaths)
            {
                string fileName = Path.GetFileName(filePath);

                CloudBlockBlob blob = container.GetBlockBlobReference(fileName);

                blob.UploadFromFile(filePath);
            }