über die mehr Kontrolle haben Upload-Prozess, können Sie Ihre Dateien in kleinere Blöcke teilen, laden Sie die Single Blöcke, zeigen den Fortschritt anhand der hochgeladenen Blöcke an und übernehmen den Upload, sobald alle Blöcke erfolgreich übertragen wurden. Sie können sogar mehrere Blöcke gleichzeitig hochladen, den Upload innerhalb von 7 Tagen anhalten/fortsetzen oder fehlerhafte Block-Uploads erneut versuchen.
Dies ist zum einen mehr Codierung, aber zum anderen mehr Kontrolle.
als Einstiegspunkt, hier einige Beispielcode in C#, da ich mit Java für Android nicht vertraut bin:
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);
}
}
In Bezug auf # 1, diese finden Sie unter: http://stackoverflow.com/questions/21175293/How-To-Track-Fortschritt-von-Async-Datei-Upload-zu-Azure-Speicher. Für # 2 und # 3 teilen Sie bitte mehr Code. Wie machen Sie Fehlerbehandlung in Ihrem Code? –