<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic chunk upload error if only one chunk  c# in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/chunk-upload-error-if-only-one-chunk-c/m-p/370348#M20892</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;InnerException = {"Cannot access a closed Stream."}&lt;/P&gt;&lt;P&gt;Message = "Error while copying content to a stream."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my code is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;using (var stream = new MemoryStream(File.ReadAllBytes(path)))&lt;BR /&gt;{&lt;BR /&gt;int numChunks = (int)Math.Ceiling((double)stream.Length / chunkSize);&lt;/P&gt;&lt;P&gt;byte[] buffer = new byte[chunkSize];&lt;BR /&gt;string sessionId = null;&lt;/P&gt;&lt;P&gt;for (var idx = 0; idx &amp;lt; numChunks; idx++)&lt;BR /&gt;{&lt;BR /&gt;var byteRead = stream.Read(buffer, 0, chunkSize);&lt;/P&gt;&lt;P&gt;using (MemoryStream memStream = new MemoryStream(buffer, 0, byteRead))&lt;BR /&gt;{&lt;BR /&gt;if (idx == 0)&lt;BR /&gt;{&lt;BR /&gt;var result = await client.Files.UploadSessionStartAsync(body: memStream);&lt;BR /&gt;sessionId = result.SessionId;&lt;BR /&gt;if (idx == numChunks - 1)&lt;BR /&gt;{&lt;BR /&gt;UploadSessionCursor cursor = new UploadSessionCursor(sessionId, (ulong)(chunkSize * idx));&lt;BR /&gt;await client.Files.UploadSessionFinishAsync(cursor, new CommitInfo(folder + "/" + fileName), memStream);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;UploadSessionCursor cursor = new UploadSessionCursor(sessionId, (ulong)(chunkSize * idx));&lt;BR /&gt;if (idx == numChunks - 1)&lt;BR /&gt;{&lt;BR /&gt;await client.Files.UploadSessionFinishAsync(cursor, new CommitInfo(folder + "/" + fileName), memStream);&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;await client.Files.UploadSessionAppendV2Async(cursor, body: memStream);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Thu, 10 Oct 2019 00:40:52 GMT</pubDate>
    <dc:creator>Julien_Do</dc:creator>
    <dc:date>2019-10-10T00:40:52Z</dc:date>
    <item>
      <title>chunk upload error if only one chunk  c#</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/chunk-upload-error-if-only-one-chunk-c/m-p/370348#M20892</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;InnerException = {"Cannot access a closed Stream."}&lt;/P&gt;&lt;P&gt;Message = "Error while copying content to a stream."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my code is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;using (var stream = new MemoryStream(File.ReadAllBytes(path)))&lt;BR /&gt;{&lt;BR /&gt;int numChunks = (int)Math.Ceiling((double)stream.Length / chunkSize);&lt;/P&gt;&lt;P&gt;byte[] buffer = new byte[chunkSize];&lt;BR /&gt;string sessionId = null;&lt;/P&gt;&lt;P&gt;for (var idx = 0; idx &amp;lt; numChunks; idx++)&lt;BR /&gt;{&lt;BR /&gt;var byteRead = stream.Read(buffer, 0, chunkSize);&lt;/P&gt;&lt;P&gt;using (MemoryStream memStream = new MemoryStream(buffer, 0, byteRead))&lt;BR /&gt;{&lt;BR /&gt;if (idx == 0)&lt;BR /&gt;{&lt;BR /&gt;var result = await client.Files.UploadSessionStartAsync(body: memStream);&lt;BR /&gt;sessionId = result.SessionId;&lt;BR /&gt;if (idx == numChunks - 1)&lt;BR /&gt;{&lt;BR /&gt;UploadSessionCursor cursor = new UploadSessionCursor(sessionId, (ulong)(chunkSize * idx));&lt;BR /&gt;await client.Files.UploadSessionFinishAsync(cursor, new CommitInfo(folder + "/" + fileName), memStream);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;UploadSessionCursor cursor = new UploadSessionCursor(sessionId, (ulong)(chunkSize * idx));&lt;BR /&gt;if (idx == numChunks - 1)&lt;BR /&gt;{&lt;BR /&gt;await client.Files.UploadSessionFinishAsync(cursor, new CommitInfo(folder + "/" + fileName), memStream);&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;await client.Files.UploadSessionAppendV2Async(cursor, body: memStream);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 00:40:52 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/chunk-upload-error-if-only-one-chunk-c/m-p/370348#M20892</guid>
      <dc:creator>Julien_Do</dc:creator>
      <dc:date>2019-10-10T00:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: chunk upload error if only one chunk  c#</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/chunk-upload-error-if-only-one-chunk-c/m-p/370509#M20898</link>
      <description>&lt;P&gt;You can use upload sessions (a.k.a. "&lt;SPAN&gt;chunk upload") to upload small files. Using the normal upload is more efficient for small files though, since you only need to make one call as opposed to two, so I would&amp;nbsp;recommend using that, despite the bit of added code complexity.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;If you do want to use upload sessions to upload small files, you would need two calls:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;`UploadSessionStartAsync`: to start the upload session and upload the data.&lt;/LI&gt;
&lt;LI&gt;`UploadSessionFinishAsync`: to finish the upload session and commit the file. Make sure you send the correct offset.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;SPAN&gt;(You can technically send the file data on either of the calls actually.)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;For the error you are getting though, I'd first check what line it's&amp;nbsp;occurring on. It looks like you're attempting to read from a stream, presumably one of the two `MemoryStream`s you open, when the stream is already closed. I&amp;nbsp;recommend stepping through with the debugger to track down the issue.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 15:27:22 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/chunk-upload-error-if-only-one-chunk-c/m-p/370509#M20898</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2019-10-10T15:27:22Z</dc:date>
    </item>
    <item>
      <title>Re: chunk upload error if only one chunk  c#</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/chunk-upload-error-if-only-one-chunk-c/m-p/370628#M20907</link>
      <description>&lt;P&gt;Yes, it was a&amp;nbsp; problem with the offset.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 00:48:41 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/chunk-upload-error-if-only-one-chunk-c/m-p/370628#M20907</guid>
      <dc:creator>Julien_Do</dc:creator>
      <dc:date>2019-10-11T00:48:41Z</dc:date>
    </item>
  </channel>
</rss>

