Question

Je suis en train d'écrire un code pour télécharger des fichiers volumineux dans les blobs à l'aide de blocs ... Quand je l'ai testé, il m'a donné un StorageClientException

Il a déclaré: L'une des entrées de requête est hors de portée

.

Je suis arrivé ce exception dans cette ligne du code:

blob.PutBlock(block, ms, null);

Voici mon code:

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";
            }
        }

Quelqu'un peut-il me dire comment résoudre ...

Était-ce utile?

La solution

Je pense que vous avez à faire ms.Position = 0 pour obtenir le retour de flux au début avant de le télécharger. (Dans le cas contraire, vraisemblablement PutBlock essaie de lire à partir du flux et trouve déjà à la fin.)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top