Note that there are some explanatory texts on larger screens.

plurals
  1. POerror: Invalid Signature when uploading files on dropbox
    primarykey
    data
    text
    <p>I am trying to develop a desktop application that uses dropbox. I am using C++, libcurl (for the requests) liboauthcpp (for the authentication) and the Rest API (from dropbox).</p> <p>Since I have successed the authentication and some more operations (list and download file), I cannot manage to upload a file. I am receiving the following error: {"error": "Invalid signature."}</p> <p>Here is my code:</p> <pre><code>m_upload_url = "https://api-content.dropbox.com/1/files/sandbox/"; OAuth::Consumer consumer(m_consumer_key, m_consumer_secret); OAuth::KeyValuePairs access_token_resp_data = OAuth::ParseKeyValuePairs(m_access_token_Response); OAuth::Token access_token = OAuth::Token::extract( access_token_resp_data ); OAuth::Client oauth = OAuth::Client(&amp;consumer, &amp;access_token); string oAuthQueryString = oauth.getURLQueryString( OAuth::Http::Post, m_upload_url); string upload_Request = (string(m_upload_url) + string("?") + oAuthQueryString); CURL *curl; CURLcode res; struct curl_httppost *formpost=NULL; struct curl_httppost *lastptr=NULL; struct curl_slist *headerlist=NULL; static const char buf[] = "Expect:"; curl_global_init(CURL_GLOBAL_ALL); /* Fill in the file upload field */ curl_formadd(&amp;formpost, &amp;lastptr, CURLFORM_COPYNAME, "file", CURLFORM_FILE, "C:/Users/Desktop/textfile.txt", CURLFORM_END); /* Fill in the filename field */ curl_formadd(&amp;formpost, &amp;lastptr, CURLFORM_COPYNAME, "name", CURLFORM_COPYCONTENTS, "textfile", CURLFORM_END); /* Fill in the submit field too, even if this is rarely needed */ curl_formadd(&amp;formpost, &amp;lastptr, CURLFORM_COPYNAME, "submit", CURLFORM_COPYCONTENTS, "send", CURLFORM_END); curl = curl_easy_init(); /* initalize custom header list (stating that Expect: 100-continue is not wanted */ headerlist = curl_slist_append(headerlist, buf); if(curl) { /* what URL that receives this POST */ curl_easy_setopt(curl, CURLOPT_URL, upload_Request.c_str()); /* only disable 100-continue header if explicitly requested */ curl_easy_setopt(curl, CURLOPT_HTTPPOST, 1L); curl_easy_setopt(curl, CURLOPT_POST, 1L); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeFunction); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); string response = string(gData); qDebug() &lt;&lt; QString::fromStdString(response); /* Check for errors */ if(res != CURLE_OK) qDebug() &lt;&lt; "curl_easy_perform() failed: %s\n" &lt;&lt; curl_easy_strerror(res); /* always cleanup */ curl_easy_cleanup(curl); /* then cleanup the formpost chain */ curl_formfree(formpost); /* free slist */ curl_slist_free_all (headerlist); } </code></pre> <p>and here is the writeFunction:</p> <pre><code>char gData[1024*1024]; unsigned int gDataLen = 0; size_t writeFunction( char *ptr, size_t size, size_t nmemb) { memcpy( &amp;( gData[gDataLen] ), ptr, (size * nmemb) ); gDataLen += (size * nmemb); gData[ gDataLen ] = '\0'; return (size * nmemb); } </code></pre> <p>Any ideas, please?</p> <p>EDIT:</p> <p>Here is the request that the present code produces: <a href="https://api-content.dropbox.com/1/files/sandbox/?oauth_consumer_key=xxxxxxxxxxxxxxx&amp;oauth_nonce=13xxxxxx83cf&amp;oauth_signature=xxxxxx%xxxxxxxxxxxxxxxxxx%xxxxx%xx&amp;oauth_signature_method=HMAC-SHA1&amp;oauth_timestamp=1371107283&amp;oauth_token=xxxxxxxxxxxxxxx&amp;oauth_version=1.0" rel="nofollow">https://api-content.dropbox.com/1/files/sandbox/?oauth_consumer_key=xxxxxxxxxxxxxxx&amp;oauth_nonce=13xxxxxx83cf&amp;oauth_signature=xxxxxx%xxxxxxxxxxxxxxxxxx%xxxxx%xx&amp;oauth_signature_method=HMAC-SHA1&amp;oauth_timestamp=1371107283&amp;oauth_token=xxxxxxxxxxxxxxx&amp;oauth_version=1.0</a></p> <p>and the request that I produse with the plaintext method: <a href="https://api-content.dropbox.com/1/files/sandbox/?oauth_version=1.0&amp;oauth_signature_method=PLAINTEXT&amp;oauth_consumer_key=xxxxxxxxxxxxxxx&amp;oauth_token=xxxxxxxxxxxxxxx&amp;oauth_signature=xxxxxxxxxxxxxxx&amp;xxxxxxxxxxxxxxx" rel="nofollow">https://api-content.dropbox.com/1/files/sandbox/?oauth_version=1.0&amp;oauth_signature_method=PLAINTEXT&amp;oauth_consumer_key=xxxxxxxxxxxxxxx&amp;oauth_token=xxxxxxxxxxxxxxx&amp;oauth_signature=xxxxxxxxxxxxxxx&amp;xxxxxxxxxxxxxxx</a></p> <p>Response that O get in both cases: {"error": "Invalid signature."}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload