<?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: How to continue if the connection is interrupted. in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-continue-if-the-connection-is-interrupted/m-p/592398#M27536</link>
    <description>&lt;P&gt;Can you elaborate on what you mean when you say "it doesn't work"? What unexpected error, output, or behavior are you getting? I recommend stepping through with the debugger first to see what is being executed and when to understand what is happening.&lt;/P&gt;</description>
    <pubDate>Thu, 21 Apr 2022 11:56:33 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2022-04-21T11:56:33Z</dc:date>
    <item>
      <title>How to continue if the connection is interrupted.</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-continue-if-the-connection-is-interrupted/m-p/592026#M27509</link>
      <description>&lt;P&gt;Hi everyone.&lt;BR /&gt;File unload question.&lt;BR /&gt;How to continue if the connection is interrupted.&lt;BR /&gt;An example of my code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))&lt;BR /&gt;{&lt;BR /&gt;int numChunks = (int)Math.Ceiling((double)stream.Length / chunkSizeByte);&lt;BR /&gt;byte[] buffer = new byte[chunkSizeByte];&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;&lt;BR /&gt;var byteRead = stream.Read(buffer, 0, chunkSizeByte);&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;try&lt;BR /&gt;{&lt;BR /&gt;var result = await dbx2.Files.UploadSessionStartAsync(close:false , body: memStream);&lt;BR /&gt;sessionId = result.SessionId;&lt;BR /&gt;Log(DateTime.Now + " - TRYING - " + i + " - FRAGMENT FIRST - " + idx);&lt;/P&gt;
&lt;P&gt;}&lt;BR /&gt;catch (Exception ui)&lt;BR /&gt;{&lt;BR /&gt;Log(DateTime.Now + " - TRYING - " + i + " - FRAGMENT FIRST ERROR - " + ui.Message);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;ulong size = chunkSize * (ulong)idx;&lt;BR /&gt;UploadSessionCursor cursor = new UploadSessionCursor(sessionId, size);&lt;/P&gt;
&lt;P&gt;if (idx == numChunks - 1)&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;await dbx2.Files.UploadSessionFinishAsync(cursor, new CommitInfo(folder + "/" + Date + filenamepath), memStream);&lt;BR /&gt;Log(DateTime.Now + " - TRYING - " + i + " - FRAGMENT LAST - " + idx);&lt;BR /&gt;}&lt;BR /&gt;catch (Exception gh)&lt;BR /&gt;{&lt;BR /&gt;Log(DateTime.Now + " - TRYING - " + i + " - FRAGMENT LAST ERROR - " + gh.Message);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;await dbx2.Files.UploadSessionAppendV2Async(cursor, close:false, body: memStream); // if there is an upload error&lt;BR /&gt;Log(DateTime.Now + " - TRYING - " + i + " - FRAGMENT PART - " + idx);&lt;BR /&gt;}&lt;BR /&gt;catch (Exception yt)&lt;BR /&gt;{&lt;BR /&gt;Log(yt.Message + " - - - " + yt.InnerException + " - - - " + yt.TargetSite);&lt;/P&gt;
&lt;P&gt;System.Threading.Thread.Sleep(pause);&lt;/P&gt;
&lt;P&gt;try&lt;BR /&gt;{&lt;BR /&gt;await dbx2.Files.UploadSessionAppendV2Async(cursor, close: false, body: memStream);&lt;BR /&gt;}&lt;BR /&gt;catch (Exception er)&lt;BR /&gt;{&lt;BR /&gt;Log("TRAYING ERROR - " + " - " + er.Message);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 16:48:17 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-continue-if-the-connection-is-interrupted/m-p/592026#M27509</guid>
      <dc:creator>roman prog 89 level_</dc:creator>
      <dc:date>2022-04-21T16:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to continue if the connection is interrupted.</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-continue-if-the-connection-is-interrupted/m-p/592149#M27512</link>
      <description>&lt;P&gt;I see you're using upload sessions to upload files by doing so in multiple pieces. With this functionality, you can catch and handle any exceptions that may occur, and then resume the process by picking up with whichever upload session call you last made.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance, if a particular call, such as&amp;nbsp;&lt;A href="https://dropbox.github.io/dropbox-sdk-dotnet/html/M_Dropbox_Api_Files_Routes_FilesUserRoutes_UploadSessionStartAsync_1.htm" target="_blank"&gt;UploadSessionStartAsync&lt;/A&gt; or &lt;A href="https://dropbox.github.io/dropbox-sdk-dotnet/html/M_Dropbox_Api_Files_Routes_FilesUserRoutes_UploadSessionAppendV2Async_1.htm" target="_blank"&gt;UploadSessionAppendV2Async&lt;/A&gt;, for instance, fails due to a network issue, you can have your code catch the exception and then retry that particular call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that in some cases, depending on the exact nature and timing of the disconnection, it's possible for the Dropbox servers to receive the complete call, without your client&amp;nbsp;receiving the response for that call. In that kind of case, the client and server may then disagree on the current offset. If that happens, on the next call for the upload session, the client will get a &lt;A href="https://dropbox.github.io/dropbox-sdk-dotnet/html/T_Dropbox_Api_Files_UploadSessionLookupError_IncorrectOffset.htm" target="_blank"&gt;UploadSessionLookupError.IncorrectOffset&lt;/A&gt; with the &lt;A href="https://dropbox.github.io/dropbox-sdk-dotnet/html/T_Dropbox_Api_Files_UploadSessionOffsetError.htm" target="_blank"&gt;UploadSessionOffsetError&lt;/A&gt; containing the &lt;A href="https://dropbox.github.io/dropbox-sdk-dotnet/html/P_Dropbox_Api_Files_UploadSessionOffsetError_CorrectOffset.htm" target="_blank"&gt;CorrectOffset&lt;/A&gt; that it can use to resume the upload session at the correct offset.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2022 16:03:51 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-continue-if-the-connection-is-interrupted/m-p/592149#M27512</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2022-04-20T16:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to continue if the connection is interrupted.</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-continue-if-the-connection-is-interrupted/m-p/592341#M27529</link>
      <description>&lt;P&gt;yes, I am doing error trapping.&lt;/P&gt;&lt;P&gt;But when I try to re-upload it doesn't work. although the connection has already been restored. I'm trying it on the bench.&lt;/P&gt;&lt;P&gt;It is noticeable that he does not even try to unload.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;else&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;await dbx2.Files.UploadSessionAppendV2Async(cursor, close:false, body: memStream); // if there is an upload error&lt;BR /&gt;Log(DateTime.Now + " - TRYING - " + i + " - FRAGMENT PART - " + idx);&lt;BR /&gt;}&lt;BR /&gt;catch (Exception yt)&lt;BR /&gt;{&lt;BR /&gt;Log(yt.Message + " - - - " + yt.InnerException + " - - - " + yt.TargetSite);&lt;/P&gt;&lt;P&gt;System.Threading.Thread.Sleep(pause);&lt;/P&gt;&lt;P&gt;try&lt;BR /&gt;{&lt;BR /&gt;await dbx2.Files.UploadSessionAppendV2Async(cursor, close: false, body: memStream); //there is no reloading at this point.&lt;BR /&gt;}&lt;BR /&gt;catch (Exception er)&lt;BR /&gt;{&lt;BR /&gt;Log("TRAYING ERROR - " + " - " + er.Message);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 05:50:07 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-continue-if-the-connection-is-interrupted/m-p/592341#M27529</guid>
      <dc:creator>roman prog 89 level_</dc:creator>
      <dc:date>2022-04-21T05:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to continue if the connection is interrupted.</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-continue-if-the-connection-is-interrupted/m-p/592398#M27536</link>
      <description>&lt;P&gt;Can you elaborate on what you mean when you say "it doesn't work"? What unexpected error, output, or behavior are you getting? I recommend stepping through with the debugger first to see what is being executed and when to understand what is happening.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2022 11:56:33 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-continue-if-the-connection-is-interrupted/m-p/592398#M27536</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2022-04-21T11:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to continue if the connection is interrupted.</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-continue-if-the-connection-is-interrupted/m-p/592607#M27562</link>
      <description>&lt;P&gt;I'll tell you more.&lt;BR /&gt;I'm testing the problem with unloading, in the debugger, manually turning off the Internet.&lt;BR /&gt;When an error occurs in UploadSessionAppendV2Async, the message is: "An error occurred while copying content to the stream. - - - System.IO.IOException: Cannot write data to transport connection: The remote host forcibly terminated the existing connection. ---&amp;gt; System .Net.Sockets.SocketException: The remote host forcibly terminated an existing connection"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Next, I intercept the error, try to re-upload through&lt;BR /&gt;UploadSessionAppendV2Async but getting error: "Access to a closed stream is not possible."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;else&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;await dbx2.Files.UploadSessionAppendV2Async(cursor, close:false, body: memStream); // if there is an upload error -&amp;nbsp;An error occurred while copying content to the stream.&lt;BR /&gt;Log(DateTime.Now + " - TRYING - " + i + " - FRAGMENT PART - " + idx);&lt;BR /&gt;}&lt;BR /&gt;catch (Exception yt)&lt;BR /&gt;{&lt;BR /&gt;Log(yt.Message + " - - - " + yt.InnerException + " - - - " + yt.TargetSite);&lt;/P&gt;&lt;P&gt;System.Threading.Thread.Sleep(pause);&lt;/P&gt;&lt;P&gt;try&lt;BR /&gt;{&lt;BR /&gt;await dbx2.Files.UploadSessionAppendV2Async(cursor, close: false, body: memStream); //there is no reloading at this point. -&amp;nbsp;Access to a closed stream is not possible.&lt;BR /&gt;}&lt;BR /&gt;catch (Exception er)&lt;BR /&gt;{&lt;BR /&gt;Log("TRAYING ERROR - " + " - " + er.Message);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don’t understand why the stream is closing, how can I connect to it again?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 06:06:45 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-continue-if-the-connection-is-interrupted/m-p/592607#M27562</guid>
      <dc:creator>roman prog 89 level_</dc:creator>
      <dc:date>2022-04-22T06:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to continue if the connection is interrupted.</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-continue-if-the-connection-is-interrupted/m-p/592734#M27568</link>
      <description>&lt;P&gt;The "Access to a closed stream is not possible" error message doesn't appear to be coming from the Dropbox API itself, so I can't offer too much help with that in particular. That said, it's likely referring to that "memStream" object. It looks like that's closed, since it was used in the first attempt, so you'd need to make a new one for the new attempt.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 15:04:14 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-continue-if-the-connection-is-interrupted/m-p/592734#M27568</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2022-04-22T15:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to continue if the connection is interrupted.</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-continue-if-the-connection-is-interrupted/m-p/593095#M27590</link>
      <description>&lt;P&gt;Thanks a lot. You're right.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2022 10:08:55 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-continue-if-the-connection-is-interrupted/m-p/593095#M27590</guid>
      <dc:creator>roman prog 89 level_</dc:creator>
      <dc:date>2022-04-25T10:08:55Z</dc:date>
    </item>
  </channel>
</rss>

