From a19fc52c329fdb0611eee7aedfb20fb0d1b9269c Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 30 May 2016 13:46:14 +0600 Subject: CLOUD: Make DropboxUploadRequest use "/upload" too If file could be uploaded in one API call, no need to create a session (which requires at least two calls: to start and then to finish it). --- backends/cloud/dropbox/dropboxstorage.cpp | 7 ++++--- backends/cloud/dropbox/dropboxuploadrequest.cpp | 12 ++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/backends/cloud/dropbox/dropboxstorage.cpp b/backends/cloud/dropbox/dropboxstorage.cpp index 1f983cec67..ab3f5d0874 100644 --- a/backends/cloud/dropbox/dropboxstorage.cpp +++ b/backends/cloud/dropbox/dropboxstorage.cpp @@ -105,6 +105,7 @@ void DropboxStorage::printBool(BoolResponse pair) { } void DropboxStorage::printUploadStatus(UploadResponse pair) { + debug(" "); UploadStatus status = pair.value; if (status.interrupted) { debug("upload interrupted by user"); @@ -118,9 +119,9 @@ void DropboxStorage::printUploadStatus(UploadResponse pair) { debug("upload HTTP response code = %ld", status.httpResponseCode); if (!status.failed) { debug("uploaded file info:"); - debug("path: %s", status.file.path().c_str()); - debug("size: %u", status.file.size()); - debug("timestamp: %u", status.file.timestamp()); + debug("\tpath: %s", status.file.path().c_str()); + debug("\tsize: %u", status.file.size()); + debug("\ttimestamp: %u", status.file.timestamp()); } } diff --git a/backends/cloud/dropbox/dropboxuploadrequest.cpp b/backends/cloud/dropbox/dropboxuploadrequest.cpp index 18e1173eef..e422793bc4 100644 --- a/backends/cloud/dropbox/dropboxuploadrequest.cpp +++ b/backends/cloud/dropbox/dropboxuploadrequest.cpp @@ -65,8 +65,16 @@ void DropboxUploadRequest::uploadNextPart() { Common::JSONObject jsonRequestParameters; if (_contentsStream->pos() == 0 || _sessionId == "") { - url += "start"; - jsonRequestParameters.setVal("close", new Common::JSONValue(false)); + if (_contentsStream->size() <= UPLOAD_PER_ONE_REQUEST) { + url = "https://content.dropboxapi.com/2/files/upload"; + jsonRequestParameters.setVal("path", new Common::JSONValue(_savePath)); + jsonRequestParameters.setVal("mode", new Common::JSONValue("overwrite")); + jsonRequestParameters.setVal("autorename", new Common::JSONValue(false)); + jsonRequestParameters.setVal("mute", new Common::JSONValue(false)); + } else { + url += "start"; + jsonRequestParameters.setVal("close", new Common::JSONValue(false)); + } } else { if (_contentsStream->size() - _contentsStream->pos() <= UPLOAD_PER_ONE_REQUEST) { url += "finish"; -- cgit v1.2.3