0

我知道我们可以使用CloudBlockblob.putBlockCloudBlockBlob.PutBlockList上传块,但这些方法没有租约 id 参数。

为此,我可以使用标头形成 httpwebrequest"x-ms-lease-id"并附加到CloudBlockblob.putBlockCloudBlockBlob.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());`

这不适用于多个块..您能否提供您的输入

4

1 回答 1

0

我不认为你可以。但是,请查看Microsoft.WindowsAzure.StorageClient.Protocol命名空间中的BlobRequest类。它具有PutBlockPutBlockList函数,允许您指定 LeaseId。

希望这可以帮助。

于 2012-10-11T05:49:59.923 回答