質問

私はそれをテストしたときに私はブロックを使用して、ブロブへのアップロード、大きなファイルのためのコードを書いています...、それは私にStorageClientExceptionを与えた。

これは、次のように述べています要求入力の1つが範囲外です。

私はこのの例外が発生しましたのコード行でます:

blob.PutBlock(block, ms, null);

ここに私のコードは次のとおりです。

protected void ButUploadBlocks_click(object sender, EventArgs e)
        {

            // store upladed file as a blob storage
            if (uplFileUpload.HasFile)
            {
                name = uplFileUpload.FileName;
                byte[] byteArray = uplFileUpload.FileBytes;
                Int64 contentLength = byteArray.Length;
                int numBytesPerBlock = 250 *1024; // 250KB per block
                int blocksCount = (int)Math.Ceiling((double)contentLength / numBytesPerBlock);  // number of blocks 
                MemoryStream ms ;
                List<string>BlockIds = new List<string>();
                string block;
                int offset = 0;

                // get refernce to the cloud blob container
                CloudBlobContainer blobContainer = cloudBlobClient.GetContainerReference("documents");

                // set the name for the uploading files
                string UploadDocName = name;

                // get the blob reference and set the metadata properties
                CloudBlockBlob blob = blobContainer.GetBlockBlobReference(UploadDocName);
                blob.Properties.ContentType = uplFileUpload.PostedFile.ContentType;

                for (int i = 0; i < blocksCount; i++, offset = offset + numBytesPerBlock)
                {
                    block = Convert.ToBase64String(BitConverter.GetBytes(i));
                    ms = new MemoryStream();
                    ms.Write(byteArray, offset, numBytesPerBlock);

                    blob.PutBlock(block, ms, null);
                    BlockIds.Add(block);
                }

                blob.PutBlockList(BlockIds);

                blob.Metadata["FILETYPE"] = "text";
            }
        }

缶誰もそれを解決する方法を教えてください...

役に立ちましたか?

解決

私はあなたがそれをアップロードする前に開始するストリームを取り戻すためにms.Position = 0をしなければならないと思います。 (そうでなければ、おそらくPutBlockストリームから読み取ろうと終わりにすでにそれを見つける。)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top