{"action":"created","comment":{"url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments/120293851","pull_request_review_id":42241911,"id":120293851,"diff_hunk":"@@ -10,43 +13,68 @@\n from corehq.util.translation import localize\n from corehq.util.log import send_HTML_email\n \n+CHUNK_SIZE = 5000000  # Read file in 5 MB chunks\n+\n \n @task\n def upload(dropbox_helper_id, access_token, size, max_retries):\n     from .models import DropboxUploadHelper\n     helper = DropboxUploadHelper.objects.get(id=dropbox_helper_id)\n-    client = DropboxClient(access_token)\n-    retries = 0\n+    dbx = Dropbox(access_token)\n \n     try:\n         with open(helper.src, 'rb') as f:\n-            uploader = client.get_chunked_uploader(f, size)\n-            while uploader.offset < size:\n-                helper.progress = uploader.offset / size\n+            chunk = f.read(CHUNK_SIZE)\n+            offset = len(chunk)\n+\n+            upload_session = dbx.files_upload_session_start(chunk)\n+\n+            while True:\n+                chunk = f.read(CHUNK_SIZE)\n+                if not chunk:\n+                    break\n+                helper.progress = offset / size\n                 helper.save()\n-                try:\n-                    uploader.upload_chunked()\n-                except ErrorResponse as e:\n-                    if retries < max_retries:\n-                        retries += 1\n-                    else:\n-                        helper.failure_reason = str(e)\n-                        helper.save()\n-                        raise e\n+                dbx.files_upload_session_append_v2(\n+                    chunk,\n+                    UploadSessionCursor(\n+                        upload_session.session_id,\n+                        offset,\n+                    ),\n+                )\n+                offset += len(chunk)\n \n-            upload = uploader.finish(helper.dest)\n+            file_metadata = dbx.files_upload_session_finish(\n+                b'',","path":"corehq/apps/dropbox/tasks.py","position":63,"original_position":63,"commit_id":"e5e5fced67ef142e54a4290fd18dffeb78e5464b","original_commit_id":"e5e5fced67ef142e54a4290fd18dffeb78e5464b","user":{"login":"mkangia","id":3864163,"avatar_url":"https://avatars0.githubusercontent.com/u/3864163?v=3","gravatar_id":"","url":"https://api.github.com/users/mkangia","html_url":"https://github.com/mkangia","followers_url":"https://api.github.com/users/mkangia/followers","following_url":"https://api.github.com/users/mkangia/following{/other_user}","gists_url":"https://api.github.com/users/mkangia/gists{/gist_id}","starred_url":"https://api.github.com/users/mkangia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkangia/subscriptions","organizations_url":"https://api.github.com/users/mkangia/orgs","repos_url":"https://api.github.com/users/mkangia/repos","events_url":"https://api.github.com/users/mkangia/events{/privacy}","received_events_url":"https://api.github.com/users/mkangia/received_events","type":"User","site_admin":false},"body":"why is this needed? an empty string?","created_at":"2017-06-06T08:33:12Z","updated_at":"2017-06-06T08:34:02Z","html_url":"https://github.com/dimagi/commcare-hq/pull/16467#discussion_r120293851","pull_request_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/16467","_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments/120293851"},"html":{"href":"https://github.com/dimagi/commcare-hq/pull/16467#discussion_r120293851"},"pull_request":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/16467"}}},"pull_request":{"url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/16467","id":124075342,"html_url":"https://github.com/dimagi/commcare-hq/pull/16467","diff_url":"https://github.com/dimagi/commcare-hq/pull/16467.diff","patch_url":"https://github.com/dimagi/commcare-hq/pull/16467.patch","issue_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/16467","number":16467,"state":"open","locked":false,"title":"Upgrade dropbox","user":{"login":"benrudolph","id":918514,"avatar_url":"https://avatars2.githubusercontent.com/u/918514?v=3","gravatar_id":"","url":"https://api.github.com/users/benrudolph","html_url":"https://github.com/benrudolph","followers_url":"https://api.github.com/users/benrudolph/followers","following_url":"https://api.github.com/users/benrudolph/following{/other_user}","gists_url":"https://api.github.com/users/benrudolph/gists{/gist_id}","starred_url":"https://api.github.com/users/benrudolph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benrudolph/subscriptions","organizations_url":"https://api.github.com/users/benrudolph/orgs","repos_url":"https://api.github.com/users/benrudolph/repos","events_url":"https://api.github.com/users/benrudolph/events{/privacy}","received_events_url":"https://api.github.com/users/benrudolph/received_events","type":"User","site_admin":false},"body":"horrible experience, but i think this should get us most of the way there until they decide to completely rewrite their api again. still need to look at the oauth flow, but that should be much more straight forward. i removed the retry functionality because i thought it was fairly pointless and adding complexity\r\n\r\nhttps://manage.dimagi.com/default.asp?254739\r\n\r\ninterrupt: @emord buddy: @mkangia ","created_at":"2017-06-05T22:36:29Z","updated_at":"2017-06-06T08:34:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"302069bd35adebd18ae609c2bda309cf143b036b","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/16467/commits","review_comments_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/16467/comments","review_comment_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/16467/comments","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/e5e5fced67ef142e54a4290fd18dffeb78e5464b","head":{"label":"dimagi:br/upgrade-dropbox","ref":"br/upgrade-dropbox","sha":"e5e5fced67ef142e54a4290fd18dffeb78e5464b","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars2.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":247278,"name":"commcare-hq","full_name":"dimagi/commcare-hq","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars2.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/commcare-hq","description":"A server-side tool to help manage community health workers, written in Django","fork":false,"url":"https://api.github.com/repos/dimagi/commcare-hq","forks_url":"https://api.github.com/repos/dimagi/commcare-hq/forks","keys_url":"https://api.github.com/repos/dimagi/commcare-hq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/commcare-hq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/commcare-hq/teams","hooks_url":"https://api.github.com/repos/dimagi/commcare-hq/hooks","issue_events_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/commcare-hq/events","assignees_url":"https://api.github.com/repos/dimagi/commcare-hq/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/commcare-hq/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/commcare-hq/tags","blobs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/commcare-hq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/commcare-hq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/commcare-hq/languages","stargazers_url":"https://api.github.com/repos/dimagi/commcare-hq/stargazers","contributors_url":"https://api.github.com/repos/dimagi/commcare-hq/contributors","subscribers_url":"https://api.github.com/repos/dimagi/commcare-hq/subscribers","subscription_url":"https://api.github.com/repos/dimagi/commcare-hq/subscription","commits_url":"https://api.github.com/repos/dimagi/commcare-hq/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/commcare-hq/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/commcare-hq/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/commcare-hq/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/commcare-hq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/commcare-hq/merges","archive_url":"https://api.github.com/repos/dimagi/commcare-hq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/commcare-hq/downloads","issues_url":"https://api.github.com/repos/dimagi/commcare-hq/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/commcare-hq/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/commcare-hq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/commcare-hq/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/commcare-hq/releases{/id}","deployments_url":"https://api.github.com/repos/dimagi/commcare-hq/deployments","created_at":"2009-07-09T17:00:07Z","updated_at":"2017-05-04T20:16:06Z","pushed_at":"2017-06-06T08:11:49Z","git_url":"git://github.com/dimagi/commcare-hq.git","ssh_url":"git@github.com:dimagi/commcare-hq.git","clone_url":"https://github.com/dimagi/commcare-hq.git","svn_url":"https://github.com/dimagi/commcare-hq","homepage":"http://www.commcarehq.org","size":349785,"stargazers_count":76,"watchers_count":76,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":89,"mirror_url":null,"open_issues_count":79,"forks":89,"open_issues":79,"watchers":76,"default_branch":"master"}},"base":{"label":"dimagi:master","ref":"master","sha":"330301b75f927904157c82103798474bc2d1ca27","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars2.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":247278,"name":"commcare-hq","full_name":"dimagi/commcare-hq","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars2.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/commcare-hq","description":"A server-side tool to help manage community health workers, written in Django","fork":false,"url":"https://api.github.com/repos/dimagi/commcare-hq","forks_url":"https://api.github.com/repos/dimagi/commcare-hq/forks","keys_url":"https://api.github.com/repos/dimagi/commcare-hq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/commcare-hq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/commcare-hq/teams","hooks_url":"https://api.github.com/repos/dimagi/commcare-hq/hooks","issue_events_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/commcare-hq/events","assignees_url":"https://api.github.com/repos/dimagi/commcare-hq/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/commcare-hq/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/commcare-hq/tags","blobs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/commcare-hq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/commcare-hq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/commcare-hq/languages","stargazers_url":"https://api.github.com/repos/dimagi/commcare-hq/stargazers","contributors_url":"https://api.github.com/repos/dimagi/commcare-hq/contributors","subscribers_url":"https://api.github.com/repos/dimagi/commcare-hq/subscribers","subscription_url":"https://api.github.com/repos/dimagi/commcare-hq/subscription","commits_url":"https://api.github.com/repos/dimagi/commcare-hq/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/commcare-hq/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/commcare-hq/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/commcare-hq/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/commcare-hq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/commcare-hq/merges","archive_url":"https://api.github.com/repos/dimagi/commcare-hq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/commcare-hq/downloads","issues_url":"https://api.github.com/repos/dimagi/commcare-hq/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/commcare-hq/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/commcare-hq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/commcare-hq/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/commcare-hq/releases{/id}","deployments_url":"https://api.github.com/repos/dimagi/commcare-hq/deployments","created_at":"2009-07-09T17:00:07Z","updated_at":"2017-05-04T20:16:06Z","pushed_at":"2017-06-06T08:11:49Z","git_url":"git://github.com/dimagi/commcare-hq.git","ssh_url":"git@github.com:dimagi/commcare-hq.git","clone_url":"https://github.com/dimagi/commcare-hq.git","svn_url":"https://github.com/dimagi/commcare-hq","homepage":"http://www.commcarehq.org","size":349785,"stargazers_count":76,"watchers_count":76,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":89,"mirror_url":null,"open_issues_count":79,"forks":89,"open_issues":79,"watchers":76,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/16467"},"html":{"href":"https://github.com/dimagi/commcare-hq/pull/16467"},"issue":{"href":"https://api.github.com/repos/dimagi/commcare-hq/issues/16467"},"comments":{"href":"https://api.github.com/repos/dimagi/commcare-hq/issues/16467/comments"},"review_comments":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/16467/comments"},"review_comment":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/16467/commits"},"statuses":{"href":"https://api.github.com/repos/dimagi/commcare-hq/statuses/e5e5fced67ef142e54a4290fd18dffeb78e5464b"}}}}
{"actor":{"display_login":"mkangia"}}