Hi,
I'm using the chunk upload and it works fine. I want to use it for all the files not just for the big ones because it is easy to trace my upload. I'm facing un error when the file is smaller than the chunk:
InnerException = {"Cannot access a closed Stream."}
Message = "Error while copying content to a stream."
my code is:
using (var stream = new MemoryStream(File.ReadAllBytes(path)))
{
int numChunks = (int)Math.Ceiling((double)stream.Length / chunkSize);
byte[] buffer = new byte[chunkSize];
string sessionId = null;
for (var idx = 0; idx < numChunks; idx++)
{
var byteRead = stream.Read(buffer, 0, chunkSize);
using (MemoryStream memStream = new MemoryStream(buffer, 0, byteRead))
{
if (idx == 0)
{
var result = await client.Files.UploadSessionStartAsync(body: memStream);
sessionId = result.SessionId;
if (idx == numChunks - 1)
{
UploadSessionCursor cursor = new UploadSessionCursor(sessionId, (ulong)(chunkSize * idx));
await client.Files.UploadSessionFinishAsync(cursor, new CommitInfo(folder + "/" + fileName), memStream);
}
}
else
{
UploadSessionCursor cursor = new UploadSessionCursor(sessionId, (ulong)(chunkSize * idx));
if (idx == numChunks - 1)
{
await client.Files.UploadSessionFinishAsync(cursor, new CommitInfo(folder + "/" + fileName), memStream);
}
else
{
await client.Files.UploadSessionAppendV2Async(cursor, body: memStream);
}
}
}
}
}
Is there any way to upload a a chunk size file with chunk upload or the only way is to use the normal upload for the files smaller than the chunk?
Thanks in advance!