bodyreader.ReadToEnd() 大きなファイルをDROPBPOXから memory/localdiskに保存せずにダウンロードしたいとします。 Parallel.Forloopを使用して複数のファイルをダウンロードしています。読み取り操作が失敗しました。 DROPBOX APIのストリームのみを使用するAzure BlobUpload
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)
{
}
は、我々は、それが後にアップロードされたファイルの50%の点で最大サイズの大きいファイルのために成功しました&をアップロードしている小さなファイルのためにこれにより、この
block = container.GetBlockBlobReference(filename);
block.UploadFromStream(stream);
のようにブロックすることなく、ただUploadFromStream
を試してみました
リクエストが破棄されました私は私の記憶/ localdiskにそれを保存せずにDROPBPOXから大きなファイルをダウンロードしたいbodyreader.ReadToEnd():以下のコードはで失敗