<?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: Java API V2 Session Upload in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165770#M5942</link>
    <description>&lt;P&gt;Hi @&lt;STRONG class="comment-author" title="Kannan G."&gt;Kannan G&amp;nbsp;&lt;/STRONG&gt;thanks for the code sample,&lt;/P&gt;
&lt;P&gt;at last i have successfully wrote an example and works like charm &lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@FBF7D2AB59A0D6E861EBF6A36F93B7E2/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt;&lt;/P&gt;
&lt;P&gt;DbxRequestConfig config = new DbxRequestConfig("dropbox/java-tutorial",&lt;BR /&gt; "en_US");&lt;BR /&gt; DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);&lt;BR /&gt; try {&lt;BR /&gt; URL url = new URL(url_d);&lt;BR /&gt; // Upload Files to Dropbox&lt;BR /&gt; String fileName = url_d.substring(url_d.lastIndexOf('/') + 1,&lt;BR /&gt; url_d.length());&lt;BR /&gt; HttpURLConnection hc = (HttpURLConnection) url.openConnection();&lt;BR /&gt; hc.addRequestProperty("Range", "bytes=0-256");&lt;BR /&gt; hc.connect();&lt;BR /&gt; DbxFiles.UploadSessionStartUploader re = client.files.uploadSessionStart();&lt;BR /&gt; re.getBody().write(IOUtils.toByteArray(hc.getInputStream()));&lt;BR /&gt; UploadSessionStartResult sa = re.finish();&lt;BR /&gt; String ss = sa.sessionId;&lt;BR /&gt; System.out.println(ss);&lt;BR /&gt; hc.disconnect();&lt;BR /&gt; HttpURLConnection hc1 = (HttpURLConnection) url.openConnection();&lt;BR /&gt; hc1.addRequestProperty("Range", "bytes=257-512");&lt;BR /&gt; hc1.connect();&lt;BR /&gt; UploadSessionAppendBuilder re1 = client.files.uploadSessionAppendBuilder(ss, 257);&lt;BR /&gt; re1.run(hc1.getInputStream());&lt;BR /&gt; hc1.disconnect();&lt;BR /&gt; HttpURLConnection hc2 = (HttpURLConnection) url.openConnection();&lt;BR /&gt; hc2.addRequestProperty("Range", "bytes=513-");&lt;BR /&gt; hc2.connect();&lt;BR /&gt; UploadSessionCursor usc = new UploadSessionCursor(ss, 513);&lt;BR /&gt; FileMetadata nn = client.files.uploadSessionFinishBuilder(&lt;BR /&gt; usc,&lt;BR /&gt; new CommitInfo("/" + fileName, DbxFiles.WriteMode.add,&lt;BR /&gt; false, new Date(), false))&lt;BR /&gt; .run(hc2.getInputStream());&lt;BR /&gt; System.out.println(nn.toStringMultiline());&lt;BR /&gt; } catch (MalformedURLException e) {&lt;BR /&gt; e.printStackTrace();&lt;BR /&gt; } catch (IOException e) {&lt;BR /&gt; e.printStackTrace();&lt;BR /&gt; } catch (UploadException e) {&lt;BR /&gt; e.printStackTrace();&lt;BR /&gt; } catch (DbxException e) {&lt;BR /&gt; e.printStackTrace();&lt;BR /&gt; }&lt;/P&gt;</description>
    <pubDate>Thu, 28 Jan 2016 03:35:51 GMT</pubDate>
    <dc:creator>pankaj kumar t.</dc:creator>
    <dc:date>2016-01-28T03:35:51Z</dc:date>
    <item>
      <title>Java API V2 Session Upload</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165764#M5936</link>
      <description>&lt;P&gt;Can you post a simple example showing how to use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;uploadSessionStart&lt;BR /&gt;uploadSessionAppendBuilder&lt;BR /&gt;uploadSessionFinishBuilder&lt;BR /&gt;&lt;BR /&gt;Including intermediate steps ... I am stuck on how to get a SessionID after calling uploadSessionStart.&lt;BR /&gt;&lt;BR /&gt;An example of this process should be available on ALL platforms! Android AP1V1, was easy, I stumbled with this on Swifty, .NET was easy. Java is not obvious.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 May 2019 09:36:33 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165764#M5936</guid>
      <dc:creator>RTS S.</dc:creator>
      <dc:date>2019-05-29T09:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Java API V2 Session Upload</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165765#M5937</link>
      <description>&lt;P&gt;I don't believe we have a sample for that,&amp;nbsp;but I'll be sure to pass this along as feedback.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you elaborate on what you're stuck on we'll be happy to help though.&amp;nbsp;Please share your code and whatever output/errors you're getting.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2016 08:22:34 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165765#M5937</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2016-01-23T08:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: Java API V2 Session Upload</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165766#M5938</link>
      <description>&lt;P&gt;This API is kind of a mess right now. &amp;nbsp;We need to sort some things out to make it clearer, but for now, this might work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;```&lt;/P&gt;
&lt;P&gt;DbxClientV2 client = ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;uploader = client.files.uploadSessionStart();&lt;/P&gt;
&lt;P&gt;String sessionId;&lt;/P&gt;
&lt;P&gt;try {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; uploader.getBody().write(first_chunk_of_upload)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; sessionId = uploader.finish()&lt;/P&gt;
&lt;P&gt;} finally {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; uploader.close()&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;uploader = client.files.uploadSessionAppend(sessionId, offset)&lt;/P&gt;
&lt;P&gt;try {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; uploader.getBody().write(second_chunk_of_upload)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; uploader.finish()&lt;/P&gt;
&lt;P&gt;} finally {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; uploader.close()&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cursor = UploadSessionCursor(sessionId, offset);&lt;/P&gt;
&lt;P&gt;FileMetadata md&amp;nbsp;= client.files.uploadSessionFinishBuilder(cursor, ...).run(third_chunk_of_upload);&lt;/P&gt;
&lt;P&gt;```&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't have time to test the code right now. &amp;nbsp;Lemme know if you run into any issues and I'll take a closer look.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2016 09:48:12 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165766#M5938</guid>
      <dc:creator>Kannan G.1</dc:creator>
      <dc:date>2016-01-23T09:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: Java API V2 Session Upload</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165767#M5939</link>
      <description>&lt;P&gt;Thank you ... I can work from this ... it was not obvious how you to get the session ID.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jan 2016 22:26:53 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165767#M5939</guid>
      <dc:creator>RTS S.</dc:creator>
      <dc:date>2016-01-23T22:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: Java API V2 Session Upload</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165768#M5940</link>
      <description>&lt;P&gt;A comment ... the interface is a little strange ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get an OutputStream that I must write to for uploading the initial chunk.&lt;/P&gt;
&lt;P&gt;I must supply an InputStream that the API reads from for the middle and last chunks.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2016 02:06:34 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165768#M5940</guid>
      <dc:creator>RTS S.</dc:creator>
      <dc:date>2016-01-24T02:06:34Z</dc:date>
    </item>
    <item>
      <title>Re: Java API V2 Session Upload</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165769#M5941</link>
      <description>&lt;P&gt;Yeah, sorry about that. &amp;nbsp;We're definitely going to change the interface to make it more consistent.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2016 04:45:44 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165769#M5941</guid>
      <dc:creator>Kannan G.1</dc:creator>
      <dc:date>2016-01-24T04:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: Java API V2 Session Upload</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165770#M5942</link>
      <description>&lt;P&gt;Hi @&lt;STRONG class="comment-author" title="Kannan G."&gt;Kannan G&amp;nbsp;&lt;/STRONG&gt;thanks for the code sample,&lt;/P&gt;
&lt;P&gt;at last i have successfully wrote an example and works like charm &lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@FBF7D2AB59A0D6E861EBF6A36F93B7E2/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt;&lt;/P&gt;
&lt;P&gt;DbxRequestConfig config = new DbxRequestConfig("dropbox/java-tutorial",&lt;BR /&gt; "en_US");&lt;BR /&gt; DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);&lt;BR /&gt; try {&lt;BR /&gt; URL url = new URL(url_d);&lt;BR /&gt; // Upload Files to Dropbox&lt;BR /&gt; String fileName = url_d.substring(url_d.lastIndexOf('/') + 1,&lt;BR /&gt; url_d.length());&lt;BR /&gt; HttpURLConnection hc = (HttpURLConnection) url.openConnection();&lt;BR /&gt; hc.addRequestProperty("Range", "bytes=0-256");&lt;BR /&gt; hc.connect();&lt;BR /&gt; DbxFiles.UploadSessionStartUploader re = client.files.uploadSessionStart();&lt;BR /&gt; re.getBody().write(IOUtils.toByteArray(hc.getInputStream()));&lt;BR /&gt; UploadSessionStartResult sa = re.finish();&lt;BR /&gt; String ss = sa.sessionId;&lt;BR /&gt; System.out.println(ss);&lt;BR /&gt; hc.disconnect();&lt;BR /&gt; HttpURLConnection hc1 = (HttpURLConnection) url.openConnection();&lt;BR /&gt; hc1.addRequestProperty("Range", "bytes=257-512");&lt;BR /&gt; hc1.connect();&lt;BR /&gt; UploadSessionAppendBuilder re1 = client.files.uploadSessionAppendBuilder(ss, 257);&lt;BR /&gt; re1.run(hc1.getInputStream());&lt;BR /&gt; hc1.disconnect();&lt;BR /&gt; HttpURLConnection hc2 = (HttpURLConnection) url.openConnection();&lt;BR /&gt; hc2.addRequestProperty("Range", "bytes=513-");&lt;BR /&gt; hc2.connect();&lt;BR /&gt; UploadSessionCursor usc = new UploadSessionCursor(ss, 513);&lt;BR /&gt; FileMetadata nn = client.files.uploadSessionFinishBuilder(&lt;BR /&gt; usc,&lt;BR /&gt; new CommitInfo("/" + fileName, DbxFiles.WriteMode.add,&lt;BR /&gt; false, new Date(), false))&lt;BR /&gt; .run(hc2.getInputStream());&lt;BR /&gt; System.out.println(nn.toStringMultiline());&lt;BR /&gt; } catch (MalformedURLException e) {&lt;BR /&gt; e.printStackTrace();&lt;BR /&gt; } catch (IOException e) {&lt;BR /&gt; e.printStackTrace();&lt;BR /&gt; } catch (UploadException e) {&lt;BR /&gt; e.printStackTrace();&lt;BR /&gt; } catch (DbxException e) {&lt;BR /&gt; e.printStackTrace();&lt;BR /&gt; }&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 03:35:51 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165770#M5942</guid>
      <dc:creator>pankaj kumar t.</dc:creator>
      <dc:date>2016-01-28T03:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: Java API V2 Session Upload</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165771#M5943</link>
      <description>&lt;P&gt;hi @&lt;STRONG class="comment-author" title="pankaj kumar t."&gt;pankaj kumar t. where is url_d, you can post the url that you use?&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2016 01:12:34 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165771#M5943</guid>
      <dc:creator>Christian</dc:creator>
      <dc:date>2016-03-10T01:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: Java API V2 Session Upload</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165772#M5944</link>
      <description>&lt;P&gt;Christian, it looks like Pankaj's example reads the data to upload from an arbitrary URL, likely specific to their app. When developing your own implementation, you can retrieve the data to upload from wherever it is in your app, e.g., a local file.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2016 02:16:32 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165772#M5944</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2016-03-10T02:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: Java API V2 Session Upload</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165773#M5945</link>
      <description>&lt;P&gt;hi @christian i had written a logic to upload files to dropbox&amp;nbsp;&lt;/P&gt;
&lt;P&gt;feel free to ask any doubt.&lt;/P&gt;
&lt;P&gt;here is the code which upload entire file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;String url_d = "&amp;lt;your download url here&amp;gt;";&lt;/P&gt;
&lt;P&gt;long buffer = 33554432; // 32mb buffer&lt;BR /&gt; DbxRequestConfig config = new DbxRequestConfig("dropbox/java-tutorial",&lt;BR /&gt; "en_US");&lt;BR /&gt; DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);&lt;BR /&gt; try {&lt;BR /&gt; URL url = new URL(url_d);&lt;BR /&gt; String sessionId = ";&lt;BR /&gt; // Upload Files to Dropbox&lt;BR /&gt; String fileName = java.net.URLDecoder.decode(url_d.substring(url_d.lastIndexOf('/') + 1,url_d.length()), "UTF-8");;&lt;BR /&gt; HttpURLConnection getLength = (HttpURLConnection) url.openConnection();&lt;BR /&gt; getLength.connect();&lt;BR /&gt; long size = getLength.getContentLengthLong();&lt;BR /&gt; // Start session&lt;BR /&gt; HttpURLConnection hc = (HttpURLConnection) url.openConnection();&lt;BR /&gt; hc.addRequestProperty("Range", "bytes=0-"+buffer);&lt;BR /&gt; hc.connect();&lt;BR /&gt; DbxFiles.UploadSessionStartUploader result = client.files.uploadSessionStart();&lt;BR /&gt; result.getBody().write(IOUtils.toByteArray(hc.getInputStream()));&lt;BR /&gt; UploadSessionStartResult sa = result.finish();&lt;BR /&gt; sessionId = sa.sessionId;&lt;BR /&gt; hc.disconnect();&lt;BR /&gt; if (size &amp;gt; 0) {&lt;BR /&gt; //System.out.println("large ");&lt;BR /&gt; &lt;BR /&gt; long s2 = buffer;&lt;BR /&gt; long tmp = 0;&lt;BR /&gt; //System.out.println("0"+" "+buffer);&lt;BR /&gt; while (tmp &amp;lt;= size &amp;amp;&amp;amp; (buffer + s2) &amp;lt; size) {&lt;BR /&gt; buffer++;&lt;BR /&gt; tmp = buffer + s2;&lt;BR /&gt; if (tmp &amp;lt; size) {&lt;BR /&gt; System.out.println(buffer + "\t" + (tmp)+"\t"+(tmp-buffer));&lt;BR /&gt; // Append to session&lt;BR /&gt; HttpURLConnection hc1 = (HttpURLConnection) url.openConnection();&lt;BR /&gt; hc1.addRequestProperty("Range", "bytes="+buffer+"-"+tmp);&lt;BR /&gt; hc1.setReadTimeout(10000);&lt;BR /&gt; hc1.connect();&lt;BR /&gt; UploadSessionAppendBuilder re1 = client.files.uploadSessionAppendBuilder(sessionId, buffer);&lt;BR /&gt; re1.run(hc1.getInputStream());&lt;BR /&gt; hc1.disconnect();&lt;BR /&gt; buffer = tmp;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; if((tmp+1)+buffer&amp;gt;size){&lt;BR /&gt; // finish session&lt;BR /&gt; HttpURLConnection hc2 = (HttpURLConnection) url.openConnection();&lt;BR /&gt; hc2.addRequestProperty("Range", "bytes="+(tmp+1)+"-"+size);&lt;BR /&gt; hc2.setReadTimeout(10000);&lt;BR /&gt; hc2.connect();&lt;BR /&gt; UploadSessionCursor usc = new UploadSessionCursor(sessionId, (tmp+1));&lt;BR /&gt; FileMetadata nn = client.files.uploadSessionFinishBuilder(&lt;BR /&gt; usc,&lt;BR /&gt; new CommitInfo("/" + fileName, DbxFiles.WriteMode.add,false, new Date(), false))&lt;BR /&gt; .run(hc2.getInputStream());&lt;BR /&gt; // End&lt;BR /&gt; System.out.println("Done"); &lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; } catch (MalformedURLException e) {&lt;BR /&gt; e.printStackTrace();&lt;BR /&gt; } catch (IOException e) {&lt;BR /&gt; e.printStackTrace();&lt;BR /&gt; } catch (UploadException e) {&lt;BR /&gt; e.printStackTrace();&lt;BR /&gt; } catch (DbxException e) {&lt;BR /&gt; e.printStackTrace();&lt;BR /&gt; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2016 10:26:49 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-API-V2-Session-Upload/m-p/165773#M5945</guid>
      <dc:creator>pankaj kumar t.</dc:creator>
      <dc:date>2016-03-10T10:26:49Z</dc:date>
    </item>
  </channel>
</rss>

