をより詳細に制御を持っていますアップロードプロセスでは、ファイルを小さなブロックに分割し、単一のファイルをアップロードすることができますアップロードされたブロックに基づいて進捗状況を表示し、すべてのブロックが正常に転送されるとすぐにアップロードをコミットします。 複数のブロックを同時にアップロードしたり、7日以内にアップロードを一時停止/再開したり、失敗したブロックアップロードを再試行することもできます。
これは一方ではより多くのコーディングですが、他方ではより多くの制御です。私は、Android用のJavaに慣れていないよので、ここでのエントリポイントとして
は、いくつかのサンプルコードは、C#である:http://stackoverflow.com/questions:
CloudBlockBlob blob = cloudBlobContainer.GetBlockBlobReference(Path.GetFileName(fileName));
int blockSize = 256 * 1024; //256 kb
using (FileStream fileStream =
new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
long fileSize = fileStream.Length;
//block count is the number of blocks + 1 for the last one
int blockCount = (int)((float)fileSize/(float)blockSize) + 1;
//List of block ids; the blocks will be committed in the order of this list
List<string> blockIDs = new List<string>();
//starting block number - 1
int blockNumber = 0;
try
{
int bytesRead = 0; //number of bytes read so far
long bytesLeft = fileSize; //number of bytes left to read and upload
//do until all of the bytes are uploaded
while (bytesLeft > 0)
{
blockNumber++;
int bytesToRead;
if (bytesLeft >= blockSize)
{
//more than one block left, so put up another whole block
bytesToRead = blockSize;
}
else
{
//less than one block left, read the rest of it
bytesToRead = (int)bytesLeft;
}
//create a blockID from the block number, add it to the block ID list
//the block ID is a base64 string
string blockId =
Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(string.Format("BlockId{0}",
blockNumber.ToString("0000000"))));
blockIDs.Add(blockId);
//set up new buffer with the right size, and read that many bytes into it
byte[] bytes = new byte[bytesToRead];
fileStream.Read(bytes, 0, bytesToRead);
//calculate the MD5 hash of the byte array
string blockHash = GetMD5HashFromStream(bytes);
//upload the block, provide the hash so Azure can verify it
blob.PutBlock(blockId, new MemoryStream(bytes), blockHash);
//increment/decrement counters
bytesRead += bytesToRead;
bytesLeft -= bytesToRead;
}
//commit the blocks
blob.PutBlockList(blockIDs);
}
catch (Exception ex)
{
System.Diagnostics.Debug.Print("Exception thrown = {0}", ex);
}
}
#1については、これを参照してください。/21175293/async-file-upload-to-azure-storageのhow-to-track-progressを使用します。 #2と#3の場合は、より多くのコードを共有してください。あなたのコードではどうやってエラー処理をしていますか? –