<?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 Re: DropBox sdk error in chunked upload “cannot access a closed file” in Discuss Dropbox Developer &amp; API</title>
    <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/DropBox-sdk-error-in-chunked-upload-cannot-access-a-closed-file/m-p/527992#M1956</link>
    <description>&lt;P&gt;I found my mistake I was using the main filestream instead of the chunked memory stream in the 1st iteration.&lt;/P&gt;</description>
    <pubDate>Sun, 20 Jun 2021 08:10:25 GMT</pubDate>
    <dc:creator>ishan_PGT</dc:creator>
    <dc:date>2021-06-20T08:10:25Z</dc:date>
    <item>
      <title>DropBox sdk error in chunked upload “cannot access a closed file”</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/DropBox-sdk-error-in-chunked-upload-cannot-access-a-closed-file/m-p/527991#M1955</link>
      <description>&lt;P&gt;&lt;SPAN&gt;So I am using the below code to ChukUpload a 150MB file and I am getting an error at &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;var byteRead = fileStream.Read(buffer, 0, (int)ChunkSize); &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;the exception says its an "cannot access a closed file.". The first chunk is uploading fine but when I enter the loop &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;"for (ulong idx = 0; idx &amp;lt; numChunks; idx++)"&amp;nbsp; 2nd time I am getting the error at fileStream.Read(buffer, 0, (int)ChunkSize);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;using(var fileStream = File.Open(Path.Combine("downloads", title), FileMode.Open)) {
  Console.WriteLine("chunked Upload");
  //ChunkUpload(remotePath, fileStream, (int)ChunkSize,dbx);
  ulong numChunks = (ulong) Math.Ceiling((double) fileStream.Length / (int) ChunkSize);
  byte[] buffer = new byte[(int) ChunkSize];
  string sessionId = null;
  for (ulong idx = 0; idx &amp;lt; numChunks; idx++) {
    var byteRead = fileStream.Read(buffer, 0, (int) ChunkSize);

    using(var memStream = new MemoryStream(buffer, 0, byteRead)) {
      if (idx == 0) {
        try {
          var result = dbx.Files.UploadSessionStartAsync(false, body: fileStream).Result;
          sessionId = result.SessionId;
          Console.WriteLine(sessionId);

        } catch (Exception ex) {
          Console.WriteLine(ex.Message);
        }
      } else {
        var cursor = new UploadSessionCursor(sessionId, (ulong)(int) ChunkSize * idx);

        if (idx == numChunks - 1) {
          FileMetadata fileMetadata = dbx.Files.UploadSessionFinishAsync(cursor, new CommitInfo(remotePath, mode: WriteMode.Overwrite.Instance), memStream).Result;
          Console.WriteLine(fileMetadata.PathDisplay);
        } else {
          dbx.Files.UploadSessionAppendV2Async(cursor, false, memStream).Wait();
        }
      }
      //}
    }
  }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 08:23:21 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/DropBox-sdk-error-in-chunked-upload-cannot-access-a-closed-file/m-p/527991#M1955</guid>
      <dc:creator>ishan_PGT</dc:creator>
      <dc:date>2021-06-21T08:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: DropBox sdk error in chunked upload “cannot access a closed file”</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/DropBox-sdk-error-in-chunked-upload-cannot-access-a-closed-file/m-p/527992#M1956</link>
      <description>&lt;P&gt;I found my mistake I was using the main filestream instead of the chunked memory stream in the 1st iteration.&lt;/P&gt;</description>
      <pubDate>Sun, 20 Jun 2021 08:10:25 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/DropBox-sdk-error-in-chunked-upload-cannot-access-a-closed-file/m-p/527992#M1956</guid>
      <dc:creator>ishan_PGT</dc:creator>
      <dc:date>2021-06-20T08:10:25Z</dc:date>
    </item>
  </channel>
</rss>

