Pregunta

Yo escribo un código para archivos de gran carga en las gotas a través de bloques ... Cuando lo probé, me dio una StorageClientException

Se declaró: Una de las entradas de petición está fuera del intervalo

.

Tengo este excepción en esta línea de código:

blob.PutBlock(block, ms, null);

Aquí está mi código:

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

Puede alguien decirme cómo solucionarlo ...

¿Fue útil?

Solución

Creo que tienes que hacer ms.Position = 0 para obtener la parte posterior flujo del inicio antes de subirlo. (De lo contrario, es de suponer PutBlock intenta leer de la corriente y se encuentra ya al final.)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top