我知道我们可以使用CloudBlockblob.putBlock
和CloudBlockBlob.PutBlockList
上传块,但这些方法没有租约ID参数。
为此,我可以使用标题"x-ms-lease-id"
形成httpwebrequest并附加到CloudBlockblob.putBlock
和CloudBlockBlob.PutBlockList
嗨Gaurav,我无法对你的回复发表评论,因此加入了它。
我尝试使用BlobRequest.PutBlock和Blobrequest.PutBlock,代码如下:
`for(int idxThread = 0; idxThread< numThreads; idxThread ++) { tasks.Add(Task.Factory.StartNew(()=> { KeyValuePair blockIdAndLength;
while (true)
{
lock (queue)
{
if (queue.Count == 0)
break;
blockIdAndLength = queue.Dequeue();
}
byte[] buff = new byte[blockIdAndLength.Value];
//copying chunks into buff from inputbyte array
Array.Copy(buffer, blockIdAndLength.Key * (long)blockIdAndLength.Value, buff, 0, blockIdAndLength.Value);
// Upload block.
string blockName = Convert.ToBase64String(BitConverter.GetBytes(
blockIdAndLength.Key));
//string blockIdString = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(string.Format("BlockId{0}", blockIdAndLength.Key.ToString("0000000"))));
/// For small files like 100 KB it works files,for large files like 10 MB,it will end up uploading only 2-3 MB
/// //Is there any better way to implement Uploading in chunks and leasing.
///
string url = blob.Uri.ToString();
if (blob.ServiceClient.Credentials.NeedsTransformUri)
{
url = blob.ServiceClient.Credentials.TransformUri(url);
}
var req = BlobRequest.Put(new Uri(url), 90, new BlobProperties(), BlobType.BlockBlob, leaseId, 0);
using (Stream writer = req.GetRequestStream())
{
writer.Write(buff,0,buff.Length);
}
blob.ServiceClient.Credentials.SignRequest(req);
req.GetResponse().Close();
}
}));
}
// Wait for all threads to complete uploading data.
Task.WaitAll(tasks.ToArray());`
这不适用于多个块。请提供您的输入
答案 0 :(得分:0)
我认为你不能。但是,请查看BlobRequest命名空间中的Microsoft.WindowsAzure.StorageClient.Protocol类。它具有PutBlock和PutBlockList功能,允许您指定LeaseId。
希望这有帮助。