Hi,
I encountered the problem "Error while copying content to a stream" when executing the above code. Is there any way to fix it?
try
{
var chunkSize = 16 * 1024 * 1024; // 16 MB
int numChunks = (int)Math.Ceiling((double)fileStream.Length / chunkSize);
byte[] buffer = new byte[chunkSize];
string sessionId = null;
var tasks = new List<Task>();
for (var idx = 0; idx < numChunks; idx++)
{
var byteRead = fileStream.Read(buffer, 0, chunkSize);
using var memStream = new MemoryStream(buffer, 0, byteRead);
if (idx == 0)
{
var result = await _client.Files.UploadSessionStartAsync(body: memStream);
sessionId = result.SessionId;
}
else
{
var cursor = new UploadSessionCursor(sessionId, (ulong)(chunkSize * idx));
if (idx == numChunks - 1)
{
await Task.WhenAll(tasks);
await _client.Files.UploadSessionFinishAsync(cursor, new CommitInfo(toPathDropbox), body: memStream);
}
else
{
tasks.Add(_client.Files.UploadSessionAppendV2Async(cursor, body: memStream));
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}