<?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 Cancelling a file upload or download using Java 2 API in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cancelling-a-file-upload-or-download-using-Java-2-API/m-p/373568#M21008</link>
    <description>&lt;P&gt;I have implemented a file upload and download capability in my Android app using the example approaches posted on GitHub. However, I need a way to interrupt the process to support the notion of 'cancel' by the user. There doesn't seem to be a way to do this? Once I get this far:&lt;/P&gt;&lt;PRE&gt;FileMetadata metadata = dbxClient.files().uploadBuilder(uploadPath + "/" + localFile.getName()) &lt;BR /&gt;.withMode(WriteMode.OVERWRITE) &lt;BR /&gt;.withClientModified(new Date(localFile.lastModified())) &lt;BR /&gt;.uploadAndFinish(in, progressListener);&lt;/PRE&gt;&lt;P&gt;This blocks internally to the API until the upload is complete. I realize I can use the 'limit' setting in a loop like this:&lt;/P&gt;&lt;PRE&gt;while ((size - uploaded) &amp;gt; CHUNKED_UPLOAD_CHUNK_SIZE)  { 
    dbxClient.files()
   .uploadSessionAppendV2(cursor)
   .uploadAndFinish(in, CHUNKED_UPLOAD_CHUNK_SIZE, progressListener); 
    uploaded += CHUNKED_UPLOAD_CHUNK_SIZE; 
    cursor = new UploadSessionCursor(sessionId, uploaded); 
}&lt;/PRE&gt;&lt;P&gt;And then check for an interrupted condition prior to initializing 'cursor' again, is this the only way? It means a delay to the user depending on how big "CHUNKED_UPLOAD_CHUNK_SIZE" is, and I'd rather not have to play games optimizing this value on the relatively low chance that the user cancels. I'd rather be able to interrupt the process whenever it needs to be interrupted.&lt;/P&gt;</description>
    <pubDate>Wed, 23 Oct 2019 13:23:33 GMT</pubDate>
    <dc:creator>tfrysinger</dc:creator>
    <dc:date>2019-10-23T13:23:33Z</dc:date>
    <item>
      <title>Cancelling a file upload or download using Java 2 API</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cancelling-a-file-upload-or-download-using-Java-2-API/m-p/373568#M21008</link>
      <description>&lt;P&gt;I have implemented a file upload and download capability in my Android app using the example approaches posted on GitHub. However, I need a way to interrupt the process to support the notion of 'cancel' by the user. There doesn't seem to be a way to do this? Once I get this far:&lt;/P&gt;&lt;PRE&gt;FileMetadata metadata = dbxClient.files().uploadBuilder(uploadPath + "/" + localFile.getName()) &lt;BR /&gt;.withMode(WriteMode.OVERWRITE) &lt;BR /&gt;.withClientModified(new Date(localFile.lastModified())) &lt;BR /&gt;.uploadAndFinish(in, progressListener);&lt;/PRE&gt;&lt;P&gt;This blocks internally to the API until the upload is complete. I realize I can use the 'limit' setting in a loop like this:&lt;/P&gt;&lt;PRE&gt;while ((size - uploaded) &amp;gt; CHUNKED_UPLOAD_CHUNK_SIZE)  { 
    dbxClient.files()
   .uploadSessionAppendV2(cursor)
   .uploadAndFinish(in, CHUNKED_UPLOAD_CHUNK_SIZE, progressListener); 
    uploaded += CHUNKED_UPLOAD_CHUNK_SIZE; 
    cursor = new UploadSessionCursor(sessionId, uploaded); 
}&lt;/PRE&gt;&lt;P&gt;And then check for an interrupted condition prior to initializing 'cursor' again, is this the only way? It means a delay to the user depending on how big "CHUNKED_UPLOAD_CHUNK_SIZE" is, and I'd rather not have to play games optimizing this value on the relatively low chance that the user cancels. I'd rather be able to interrupt the process whenever it needs to be interrupted.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2019 13:23:33 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cancelling-a-file-upload-or-download-using-Java-2-API/m-p/373568#M21008</guid>
      <dc:creator>tfrysinger</dc:creator>
      <dc:date>2019-10-23T13:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: Cancelling a file upload or download using Java 2 API</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cancelling-a-file-upload-or-download-using-Java-2-API/m-p/373741#M21014</link>
      <description>&lt;P&gt;When using the Dropbox API v2 Java SDK, you can cancel an in-progress upload by using &lt;A href="https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.1.x/com/dropbox/core/DbxUploader.html#abort--" target="_self"&gt;the&amp;nbsp;DbxUploader.abort method&lt;/A&gt;. That's available on its sub-classes for various use cases, such as&amp;nbsp;&lt;A href="https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.1.x/com/dropbox/core/v2/files/UploadUploader.html" target="_self"&gt;UploadUploader&lt;/A&gt;,&amp;nbsp;&lt;A href="https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.1.x/com/dropbox/core/v2/files/UploadSessionStartUploader.html" target="_self"&gt;UploadSessionStartUploader&lt;/A&gt;,&amp;nbsp;&lt;A href="https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.1.x/com/dropbox/core/v2/files/UploadSessionAppendV2Uploader.html" target="_self"&gt;UploadSessionAppendV2Uploader&lt;/A&gt;, and&amp;nbsp;&lt;A href="https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.1.x/com/dropbox/core/v2/files/UploadSessionFinishUploader.html" target="_self"&gt;UploadSessionFinishUploader&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, you can get the&amp;nbsp;&lt;A href="https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.1.x/com/dropbox/core/v2/files/UploadUploader.html" target="_self"&gt;UploadUploader&lt;/A&gt;&amp;nbsp;from&amp;nbsp;&lt;A href="https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.1.x/com/dropbox/core/v2/files/DbxUserFilesRequests.html#upload-java.lang.String-" target="_self"&gt;upload&lt;/A&gt; or&amp;nbsp;&lt;A href="https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.1.x/com/dropbox/core/v2/files/UploadBuilder.html#start--" target="_self"&gt;UploadBuilder.start&lt;/A&gt; (as opposed to directly chaining on&amp;nbsp;uploadAndFinish).&lt;/P&gt;
&lt;P&gt;That would look something like this: first, set up and save your uploader:&lt;/P&gt;
&lt;PRE&gt;UploadUploader uploader = dbxClient.files().uploadBuilder(path)
                        .withMode(WriteMode.OVERWRITE)
                        .withClientModified(new Date(localFile.lastModified()))
                        .start();&lt;/PRE&gt;
&lt;P&gt;Then, start the upload (maybe on another thread):&lt;/P&gt;
&lt;PRE&gt;fileMetadata = uploader.uploadAndFinish(in, progressListener);&lt;/PRE&gt;
&lt;P&gt;And if/when you need to cancel that upload:&lt;/P&gt;
&lt;PRE&gt;if (someCondition) {
    uploader.abort();
}&lt;/PRE&gt;
&lt;P&gt;The &lt;A href="https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.1.x/com/dropbox/core/DbxDownloader.html" target="_self"&gt;DbxDownloader&lt;/A&gt; class doesn't offer an abort method, but you can use &lt;A href="https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.1.x/com/dropbox/core/DbxDownloader.html#getInputStream--" target="_self"&gt;DbxDownloader.getInputStream&lt;/A&gt; to get an InputStream so you can more directly control if/when/how much data to read from it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2019 15:53:36 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cancelling-a-file-upload-or-download-using-Java-2-API/m-p/373741#M21014</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2019-10-23T15:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: Cancelling a file upload or download using Java 2 API</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cancelling-a-file-upload-or-download-using-Java-2-API/m-p/373903#M21024</link>
      <description>&lt;P&gt;Hi - that helps a lot on the upload area.&lt;/P&gt;&lt;P&gt;For the download, I'm not sure I follow how getting a reference to the InputStream helps here. I suppose if I could read from it in "chunks" similar to upload, I could check every "chunk" to see if a cancel had been indicated, but I'm not sure how to do that.&lt;/P&gt;&lt;P&gt;Do you have a small code example to share?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 03:29:44 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cancelling-a-file-upload-or-download-using-Java-2-API/m-p/373903#M21024</guid>
      <dc:creator>tfrysinger</dc:creator>
      <dc:date>2019-10-24T03:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: Cancelling a file upload or download using Java 2 API</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cancelling-a-file-upload-or-download-using-Java-2-API/m-p/374000#M21028</link>
      <description>&lt;P&gt;Is something like this appropriate?&lt;/P&gt;&lt;PRE&gt;                DbxDownloader&amp;lt;FileMetadata&amp;gt; downloader = dbxClient.files().downloadBuilder(dropboxPath + "/" + localFile)
                        .start();
                InputStream inputStream = downloader.getInputStream();
                int count;
                long bytesWritten = 0;
                boolean keepGoin = true;
                byte data[] = new byte[WRITE_BUFFER];
                while ( keepGoin &amp;amp;&amp;amp; ((count = inputStream.read(data, 0, WRITE_BUFFER)) != -1)) {
                    outputStream.write(data, 0, count);
                    bytesWritten += count;
                    progressListener.onProgress(bytesWritten);
                    if ( listener != null ) {
                        keepGoin = listener.cancelFileOperation();
                    }
                }
                if ( bytesWritten != size) {
                    // Means we were interrupted
                    throw new UserCancelException(InTouch.getInstance().getString(R.string.interrupted_exception_cancel_xfer));
                }&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Oct 2019 13:22:49 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cancelling-a-file-upload-or-download-using-Java-2-API/m-p/374000#M21028</guid>
      <dc:creator>tfrysinger</dc:creator>
      <dc:date>2019-10-24T13:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: Cancelling a file upload or download using Java 2 API</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cancelling-a-file-upload-or-download-using-Java-2-API/m-p/374017#M21031</link>
      <description>&lt;P&gt;Apologies I didn't have a code sample for that handy, but yes, what you just shared looks like what I had in mind.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 13:49:51 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cancelling-a-file-upload-or-download-using-Java-2-API/m-p/374017#M21031</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2019-10-24T13:49:51Z</dc:date>
    </item>
    <item>
      <title>Re: Cancelling a file upload or download using Java 2 API</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cancelling-a-file-upload-or-download-using-Java-2-API/m-p/374088#M21036</link>
      <description>&lt;P&gt;Greg -&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once I issue .start(), do I need to do anything other than close the streams to correctly end this transaction?&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 16:52:35 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cancelling-a-file-upload-or-download-using-Java-2-API/m-p/374088#M21036</guid>
      <dc:creator>tfrysinger</dc:creator>
      <dc:date>2019-10-24T16:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: Cancelling a file upload or download using Java 2 API</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cancelling-a-file-upload-or-download-using-Java-2-API/m-p/374106#M21037</link>
      <description>&lt;P&gt;You should just use&amp;nbsp;&lt;A href="https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.1.x/com/dropbox/core/DbxDownloader.html#close--" target="_self"&gt;DbxDownloader.close&lt;/A&gt; when you're finished with the downloader (which will close the&amp;nbsp;InputStream returned by&amp;nbsp;getInputStream for you), in addition to closing any streams you opened yourself.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 17:22:41 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Cancelling-a-file-upload-or-download-using-Java-2-API/m-p/374106#M21037</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2019-10-24T17:22:41Z</dc:date>
    </item>
  </channel>
</rss>

