<?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: API v2 upload_session/append_v2 doc help in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/API-v2-upload-session-append-v2-doc-help/m-p/180692#M7400</link>
    <description>&lt;P&gt;Thanks Gregory, you save my life. I'll check it later. Thank you!&lt;/P&gt;</description>
    <pubDate>Thu, 04 Aug 2016 14:58:45 GMT</pubDate>
    <dc:creator>David W.152</dc:creator>
    <dc:date>2016-08-04T14:58:45Z</dc:date>
    <item>
      <title>API v2 upload_session/append_v2 doc help</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/API-v2-upload-session-append-v2-doc-help/m-p/180690#M7398</link>
      <description>&lt;P&gt;Hi dropbox team,&lt;/P&gt;
&lt;P&gt;I have no idea how to upload a larger file (&amp;gt;= 1GB) via upload_session/* API.&lt;/P&gt;
&lt;P&gt;Can not find any full example code with that.&lt;/P&gt;
&lt;P&gt;APIs:&lt;/P&gt;
&lt;P&gt;/upload_session/start&lt;BR /&gt;/upload_session/append_v2&lt;BR /&gt;/upload_session/finish&lt;/P&gt;
&lt;P&gt;Logs:&lt;/P&gt;
&lt;P&gt;---- first try ---------------------------------&lt;/P&gt;
&lt;P&gt;Step 1:&lt;BR /&gt; Request: &lt;BR /&gt; curl "/upload_session/start" file="" \&lt;BR /&gt; --header "Dropbox-API-Arg: {}"&lt;BR /&gt; Response:&lt;BR /&gt; status code: 200&lt;BR /&gt; JSON:&lt;BR /&gt; {&lt;BR /&gt; "session_id" = AAA123456;&lt;BR /&gt; }&lt;/P&gt;
&lt;P&gt;Step 2:&lt;BR /&gt; Request: &lt;BR /&gt; curl "/upload_session/append_v2" file="test_file_5MB_for_upload.bin" \&lt;BR /&gt; --header {\"cursor\": {\"session_id\": \"AAA123456\",\"offset\": 0},\"close\": false}"&lt;BR /&gt; Response:&lt;BR /&gt; status code: 200&lt;BR /&gt; TEXT:&lt;BR /&gt; &amp;lt;null&amp;gt;&lt;BR /&gt;Step 3:&lt;BR /&gt; Request:&lt;BR /&gt; curl "/upload_session/finish" file="" \&lt;BR /&gt; --header "Dropbox-API-Arg" = "{\"commit\":{\"path\":\"\\/test_file_5MB_for_upload.bin\",\"autorename\":false,\"mute\":true,\"mode\":\"overwrite\"},\"cursor\":{\"offset\":5242880,\"session_id\":\"AAA123456\"}}"&lt;BR /&gt; Response:&lt;BR /&gt; status code: 200&lt;BR /&gt; JSON:&lt;BR /&gt; {&lt;BR /&gt; "client_modified" = "2016-xx-xxTxx:xx:xxZ";&lt;BR /&gt; id = "id:uNFAAA123456";&lt;BR /&gt; name = "test_file_5MB_for_upload.bin";&lt;BR /&gt; "path_display" = "/test_file_5MB_for_upload.bin";&lt;BR /&gt; "path_lower" = "/test_file_5mb_for_upload.bin";&lt;BR /&gt; rev = 325399abc05;&lt;BR /&gt; "server_modified" = "2016-xx-xxTxx:xx:xxZ";&lt;BR /&gt; size = 5242880;&lt;BR /&gt; }&lt;/P&gt;
&lt;P&gt;---- second try ---------------------------------&lt;/P&gt;
&lt;P&gt;Step 1:&lt;BR /&gt; Request: &lt;BR /&gt; curl "/upload_session/start" file="test_file_5MB_for_upload.bin" \&lt;BR /&gt; --header "Dropbox-API-Arg: {}"&lt;BR /&gt; Response:&lt;BR /&gt; status code: 200&lt;BR /&gt; JSON:&lt;BR /&gt; {&lt;BR /&gt; "session_id" = AAA123456;&lt;BR /&gt; }&lt;/P&gt;
&lt;P&gt;Step 2:&lt;BR /&gt; Request:&lt;BR /&gt; curl "/upload_session/finish" file="" \&lt;BR /&gt; --header "Dropbox-API-Arg" = "{\"commit\":{\"path\":\"\\/test_file_5MB_for_upload.bin\",\"autorename\":false,\"mute\":true,\"mode\":\"overwrite\"},\"cursor\":{\"offset\":5242880,\"session_id\":\"AAA123456\"}}"&lt;BR /&gt; Response:&lt;BR /&gt; status code: 200&lt;BR /&gt; JSON:&lt;BR /&gt; {&lt;BR /&gt; "client_modified" = "2016-xx-xxTxx:xx:xxZ";&lt;BR /&gt; id = "id:uNFAAA123456";&lt;BR /&gt; name = "test_file_5MB_for_upload.bin";&lt;BR /&gt; "path_display" = "/test_file_5MB_for_upload.bin";&lt;BR /&gt; "path_lower" = "/test_file_5mb_for_upload.bin";&lt;BR /&gt; rev = 325399abc05;&lt;BR /&gt; "server_modified" = "2016-xx-xxTxx:xx:xxZ";&lt;BR /&gt; size = 5242880;&lt;BR /&gt; }&lt;/P&gt;
&lt;P&gt;---- third try ---------------------------------&lt;/P&gt;
&lt;P&gt;Step 1:&lt;BR /&gt; Request: &lt;BR /&gt; curl "/upload_session/start" file="" \&lt;BR /&gt; --header "Dropbox-API-Arg: {}"&lt;BR /&gt; Response:&lt;BR /&gt; status code: 200&lt;BR /&gt; JSON:&lt;BR /&gt; {&lt;BR /&gt; "session_id" = AAA12345678;&lt;BR /&gt; }&lt;/P&gt;
&lt;P&gt;Step 2:&lt;BR /&gt; Request: &lt;BR /&gt; curl "/upload_session/append_v2" file="test_file_1GB_for_upload.bin" \&lt;BR /&gt; --header {\"cursor\": {\"session_id\": \"AAA12345678\",\"offset\": 0},\"close\": false}"&lt;BR /&gt; Response:&lt;BR /&gt; Response:&lt;BR /&gt; status code: 413&lt;BR /&gt; TEXT:&lt;BR /&gt; &amp;lt;DOCTYPE html&amp;gt;&lt;BR /&gt; &amp;lt;title&amp;gt;4xx&amp;lt;/title&amp;gt;&lt;BR /&gt; ...&lt;BR /&gt; &amp;lt;/html&amp;gt;&lt;/P&gt;
&lt;P&gt;----------------------------------------------------&lt;/P&gt;
&lt;P&gt;Would be very grateful for any suggestion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 09:31:09 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/API-v2-upload-session-append-v2-doc-help/m-p/180690#M7398</guid>
      <dc:creator>David W.152</dc:creator>
      <dc:date>2019-05-29T09:31:09Z</dc:date>
    </item>
    <item>
      <title>Re: API v2 upload_session/append_v2 doc help</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/API-v2-upload-session-append-v2-doc-help/m-p/180691#M7399</link>
      <description>&lt;P&gt;Hi David, I unfortunately don't have a sample of using upload sessions in bash/curl directly, but here are some examples using the Python&amp;nbsp;and .NET&amp;nbsp;SDKs, which should serve as a useful reference for the necessary logic:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;# This uses the Dropbox Python SDK https://github.com/dropbox/dropbox-sdk-python to upload a file to the Dropbox API from the local file as specified by `file_path` to the remote path as specified by `dest_path`. It also chooses whether or not to use an upload session based on the size of the file:

    f = open(file_path)
    file_size = os.path.getsize(file_path)

    CHUNK_SIZE = 4 * 1024 * 1024

    if file_size &amp;lt;= CHUNK_SIZE:

        print dbx.files_upload(f.read(), dest_path)

    else:

        upload_session_start_result = dbx.files_upload_session_start(f.read(CHUNK_SIZE))
        cursor = dropbox.files.UploadSessionCursor(session_id=upload_session_start_result.session_id,
                                                   offset=f.tell())
        commit = dropbox.files.CommitInfo(path=dest_path)

        while f.tell() &amp;lt; file_size:
            if ((file_size - f.tell()) &amp;lt;= CHUNK_SIZE):
                print dbx.files_upload_session_finish(f.read(CHUNK_SIZE),
                                                cursor,
                                                commit)
            else:
                dbx.files_upload_session_append_v2(f.read(CHUNK_SIZE),
                                                cursor)
                cursor.offset = f.tell()

    f.close()&lt;/PRE&gt;
&lt;PRE&gt;// This example uses the Dropbox .NET library https://github.com/dropbox/dropbox-sdk-dotnet to upload a file to a Dropbox account, using upload sessions for larger files:

    private async Task Upload(string localPath, string remotePath)
    {
        const int ChunkSize = 4096 * 1024;
        using (var fileStream = File.Open(localPath, FileMode.Open))
        {
            if (fileStream.Length &amp;lt;= ChunkSize)
            {
                await this.client.Files.UploadAsync(remotePath, body: fileStream);
            }
            else
            {
                await this.ChunkUpload(remotePath, fileStream, (int)ChunkSize);
            }
        }
    }

    private async Task ChunkUpload(String path, FileStream stream, int chunkSize)
    {
        ulong numChunks = (ulong)Math.Ceiling((double)stream.Length / chunkSize);
        byte[] buffer = new byte[chunkSize];
        string sessionId = null;
        for (ulong idx = 0; idx &amp;lt; numChunks; idx++)
        {
            var byteRead = stream.Read(buffer, 0, chunkSize);

            using (var memStream = new MemoryStream(buffer, 0, byteRead))
            {
                if (idx == 0)
                {
                    var result = await this.client.Files.UploadSessionStartAsync(false, memStream);
                    sessionId = result.SessionId;
                }
                else
                {
                    var cursor = new UploadSessionCursor(sessionId, (ulong)chunkSize * idx);

                    if (idx == numChunks - 1)
                    {
                        FileMetadata fileMetadata = await this.client.Files.UploadSessionFinishAsync(cursor, new CommitInfo(path), memStream);
                        Console.WriteLine (fileMetadata.PathDisplay);
                    }
                    else
                    {
                        await this.client.Files.UploadSessionAppendV2Async(cursor, false, memStream);
                    }
                }
            }
        }
    }
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Feb 2019 16:07:44 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/API-v2-upload-session-append-v2-doc-help/m-p/180691#M7399</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2019-02-19T16:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: API v2 upload_session/append_v2 doc help</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/API-v2-upload-session-append-v2-doc-help/m-p/180692#M7400</link>
      <description>&lt;P&gt;Thanks Gregory, you save my life. I'll check it later. Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2016 14:58:45 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/API-v2-upload-session-append-v2-doc-help/m-p/180692#M7400</guid>
      <dc:creator>David W.152</dc:creator>
      <dc:date>2016-08-04T14:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: API v2 upload_session/append_v2 doc help</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/API-v2-upload-session-append-v2-doc-help/m-p/329491#M19265</link>
      <description>&lt;P&gt;Hi Greg! Is possible to update the SO Documentation links, they're broken now &lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@B0F70D28791EB05FA3EA0C3BDDF08EE3/emoticons/1f61e.png" alt=":disappointed_face:" title=":disappointed_face:" /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Feb 2019 22:14:51 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/API-v2-upload-session-append-v2-doc-help/m-p/329491#M19265</guid>
      <dc:creator>ivanhigueram</dc:creator>
      <dc:date>2019-02-18T22:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: API v2 upload_session/append_v2 doc help</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/API-v2-upload-session-append-v2-doc-help/m-p/329624#M19276</link>
      <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/994001"&gt;@ivanhigueram&lt;/a&gt;&amp;nbsp;I've updated&amp;nbsp;&lt;A href="https://www.dropboxforum.com/t5/API-Support-Feedback/API-v2-upload-session-append-v2-doc-help/m-p/180691/highlight/true#M7399" target="_self"&gt;my earlier post&lt;/A&gt;&amp;nbsp;to embed the code snippets from the now-defunct StackOverflow Documentation pages directly.&amp;nbsp;Hope this helps!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Feb 2019 16:08:04 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/API-v2-upload-session-append-v2-doc-help/m-p/329624#M19276</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2019-02-19T16:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: API v2 upload_session/append_v2 doc help</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/API-v2-upload-session-append-v2-doc-help/m-p/329626#M19278</link>
      <description>&lt;P&gt;Hi &lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/10"&gt;@Greg-DB&lt;/a&gt;&amp;nbsp;Thanks for replying back and point me to the code links. I recently opened another issue in the forum (&lt;A href="https://www.dropboxforum.com/t5/API-Support-Feedback/Python-V2-How-to-do-batch-upload/m-p/329517" target="_blank"&gt;https://www.dropboxforum.com/t5/API-Support-Feedback/Python-V2-How-to-do-batch-upload/m-p/329517&lt;/A&gt;) with my specific problem using batch upload.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Feb 2019 16:17:07 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/API-v2-upload-session-append-v2-doc-help/m-p/329626#M19278</guid>
      <dc:creator>ivanhigueram</dc:creator>
      <dc:date>2019-02-19T16:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: API v2 upload_session/append_v2 doc help</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/API-v2-upload-session-append-v2-doc-help/m-p/329627#M19279</link>
      <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/994001"&gt;@ivanhigueram&lt;/a&gt;&amp;nbsp;We'll review your other post and follow up there as soon we can.&amp;nbsp;Thanks in advance for your patience.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Feb 2019 16:16:06 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/API-v2-upload-session-append-v2-doc-help/m-p/329627#M19279</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2019-02-19T16:16:06Z</dc:date>
    </item>
  </channel>
</rss>

