Der folgende Code schlägt fehl bei: bodycreader.ReadToEnd() Ich möchte große Dateien von DROPBPOX herunterladen, ohne es in meinem Speicher/Localdisk zu speichern. Ich verwende Parallel.Forloop, um mehrere Dateien herunterzuladen.Lesevorgang fehlgeschlagen. Large Files Azure BlobUpload mit nur Stream von DROPBOX api
public static DropboxClient dropboxClient;
var response = await dropboxClient.Files.DownloadAsync(file[0]);
var fileStream = await response.GetContentAsStreamAsync();
try {
container = obj.BloBHandle();
table = obj.TableHandle();
StreamReader bodyReader = new StreamReader(filepath);
string bodyString = bodyReader.ReadToEnd();
block = container.GetBlockBlobReference(filename);
int blockSize = 4 * 1024 * 1024; //256 kb
int fileSize = bodyString.Length;
//long fileSize = filepath.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;
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];
filepath.Read(bytes, 0, bytesToRead);
// Stream stream = new MemoryStream(bytesToRead);
//calculate the MD5 hash of the byte array
string blockHash = GetMD5HashFromStream(bytes);
//upload the block, provide the hash so Azure can verify it
block.PutBlock(blockId, new MemoryStream(bytes), blockHash);
//increment/decrement counters
bytesRead += bytesToRead;
bytesLeft -= bytesToRead;
}
//commit the blocks
block.PutBlockList(blockIDs);
}
catch (Exception ex)
{
}
dann haben wir versucht, ohne Blöcke UploadFromStream nur
Gefällt Ihnen dieses
block = container.GetBlockBlobReference(filename);
block.UploadFromStream(stream);
Damit für kleine Dateien, die es erfolgreich & für große Dateien bis zu 50% der Datei hochzuladen es später wird das Hochladen wir bekommen Ausnahme wie
Anfrage wurde abgebrochen Anfrage wurde
abgesagt