答案 0 :(得分:1)
我无法使用 GetBlockBlobReference( fileName )获得blockBlob的绝对路径。下面的代码解决了我的问题。我得到了清单,然后使用LINQ来获取具有绝对路径详细信息的blockBlob。 This post helped as well
public class ConcurrentMap<TKey, TValue> : Map<TKey, TValue>
{
protected SlimLockWrapper __lock = new SlimLockWrapper();
protected SlimLockWrapper _lock
{
get
{
if (__lock == null)
{
__lock = new SlimLockWrapper();
}
return __lock;
}
}
public ConcurrentMap()
: this(ProviderDefault)
{
}
public ConcurrentMap(Func<TKey, TValue> provider)
: base(provider)
{
}
public ConcurrentMap(SerializationInfo info, StreamingContext context)
: this(ProviderDefault)
{
}
public override TValue this[TKey key]
{
get { return this._Get(key); }
set { this._Set(key, value); }
}
public override TValue this[TKey key, TValue fallback]
{
get
{
return _lock.Read(() => base[key, fallback]);
}
}
public override void Add(TKey key, TValue value)
{
_lock.Write(() => this._Set(key, value));
}
public override void Add(KeyValuePair<TKey, TValue> item)
{
_lock.Write(() => this._Set(item.Key, item.Value));
}
public override void AddRange(IEnumerable<KeyValuePair<TKey, TValue>> enumerable)
{
_lock.Write(() => {
foreach (var pair in enumerable) {
this._Set(pair.Key, pair.Value);
}
});
}
public override bool ContainsKey(TKey key)
{
return _lock.Read(() => this._dictionary.ContainsKey(key));
}
public override bool ContainsValue(TValue value)
{
return _lock.Read(() => this._dictionary.ContainsValue(value));
}
public override bool Contains(KeyValuePair<TKey, TValue> item)
{
return _lock.Read(() => this._dictionary.Contains(item));
}
public override ICollection<TKey> Keys
{
get { return _lock.Read(() => this._dictionary.Keys.ToList()); }
}
public override ICollection<TValue> Values
{
get { return _lock.Read(() => this._dictionary.Values.ToList()); }
}
public override bool Remove(TKey key)
{
return _lock.Write(() => this._dictionary.Remove(key));
}
public override bool TryGetValue(TKey key, out TValue value)
{
_lock.Lock.EnterReadLock();
try {
return this._dictionary.TryGetValue(key, out value);
}
finally {
_lock.Lock.ExitReadLock();
}
}
public override void Clear()
{
_lock.Write(() => this._dictionary = new Dictionary<TKey,TValue>());
}
public override int Count
{
get { return _lock.Read(() => this._dictionary.Count); }
}
public override bool Remove(KeyValuePair<TKey, TValue> item)
{
return _lock.Write(() => (this._dictionary as IDictionary<TKey, TValue>).Remove(item));
}
public override IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
return _lock.Read(() => this._dictionary.ToList().GetEnumerator());
}
public override void CopyTo(KeyValuePair<TKey, TValue>[] array, int index)
{
_lock.Read(() => (this._dictionary as IDictionary<TKey, TValue>).CopyTo(array, index));
}
}
更正我是否还有其他有效方法可以从容器中的目录列表中提取blob信息。
答案 1 :(得分:0)
只需使用Gaurav Mantri的answer中提到的ListBlobs
即可检索所需子文件夹中的所有文件(blob)。然后遍历并下载:
var storageAccount = CloudStorageAccount.Parse("yourConnectionString");
var client = storageAccount.CreateCloudBlobClient();
var container = client.GetContainerReference("yourContainer");
var blobs = container.ListBlobs(prefix: "subdirectory1/subdirectory2", useFlatBlobListing: true);
foreach (var blob in blobs)
{
blob.DownloadToFileAsync("yourFilePath");
}
答案 2 :(得分:0)
以下解决方案有助于访问目录(或文件夹路径)下的单个文件绝对路径。
public static String GetBlobUri(string dirPath, string fileName)
{
//Get a reference to a blob within the container.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("Blob Key");
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("Blob Container");
CloudBlockBlob blockBlob = container.GetBlockBlobReference(dirPath+fileName);
return blockBlob.Uri.AbsoluteUri;
}
希望这可以帮助尝试访问基于多级目录(Level1 / Level2 / Level3)路径的Blob文件路径。