How to Upload Large File By Splitting Into Blocks In Windows Azure Blob Storage Using Java RRS feed


  • hi Sir,

    关于将文件分割为block blob,并且上传至Blob stroage, 基本思路如下:

    1.split large file and upload each block blob

    // list of all uploaded block ids. need for commiting them at the end
    var blockIdList = new List<string>();
    using (var file = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            // block counter
            var blockId = 0;
            // open file
            while (file.Position < file.Length)
                // calculate buffer size (blockSize in KB)   
                var bufferSize = blockSize * 1024 < file.Length - file.Position ? blockSize * 1024 : file.Length - file.Position;
                var buffer = new byte[bufferSize]; 
                // read data to buffer
                file.Read(buffer, 0, buffer.Length); 
                // save data to memory stream and put to storage
                using (var stream = new MemoryStream(buffer))
                    // set stream position to start
                    stream.Position = 0;
                    // convert block id to Base64 Encoded string      
                    var blockIdBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(blockId.ToString(CultureInfo.InvariantCulture)));
                    blob.PutBlock(blockIdBase64, stream, null);
                    // increase block id

    2. commit the block blob list:


    你可以在下载Azure storage client library for java 的包从这个页面:

    如果倾向于使用REST API, 可参考这个文档:

    同时可参考 Gaurav使用js和html写成的上传实例:,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年10月8日 1:37