I'm trying to upload a file using libcurl. The code reports an OK upload, but the file does not appear. This is the equivalent curl command and it works:
curl -X POST https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer [my token] " \
--header "Dropbox-API-Arg: {\"mode\":\"add\",\"path\":\"/dummy.txt\"}" \
--header "Content-Type: application/octet-stream" \
--data-binary @dummy.txt
The following libcurl code executes and seems to work, but the file does not appear on Dropbox.
fpt_debug=fopen("D:\\trace.txt","wb");
curl_easy_reset(curl_handle);
curl_easy_setopt(curl_handle,CURLOPT_STDERR,fpt_debug);
curl_easy_setopt(curl_handle,CURLOPT_URL,"https://content.dropboxapi.com/2/files/upload");
curl_easy_setopt(curl_handle,CURLOPT_VERBOSE,1); /* prints info to stderr, for debugging */
curl_easy_setopt(curl_handle,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2TLS);
curl_headers=NULL;
sprintf(text,"Authorization: Bearer %s",DropboxToken);
curl_headers=curl_slist_append(curl_headers,text);
sprintf(text,"Dropbox-API-Arg: {\"path\":\"%s\"}","/dummy.txt");
curl_headers=curl_slist_append(curl_headers,text);
sprintf(text,"Content-Type: application/octet-stream");
curl_headers=curl_slist_append(curl_headers,text);
curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER,curl_headers);
fpt=fopen("D:\\dummy.txt","rb");
curl_easy_setopt(curl_handle,CURLOPT_READFUNCTION,read_cb);
curl_easy_setopt(curl_handle,CURLOPT_UPLOAD,1L);
curl_easy_setopt(curl_handle,CURLOPT_URL,"https://content.dropboxapi.com/2/files/upload");
curl_easy_setopt(curl_handle,CURLOPT_READDATA,fpt);
curl_easy_setopt(curl_handle,CURLOPT_INFILESIZE_LARGE,(curl_off_t)(total_bytes); /* 49 bytes in dummy.txt */
curlret=curl_easy_perform(curl_handle);
fclose(fpt);
curl_slist_free_all(curl_headers);
The call to curl_easy_perform() returns CURLE_OK (0). The verbose curl output is below. But the file does not appear in Dropbox. Any ideas?
- Host content.dropboxapi.com:443 was resolved.
* IPv6: 2620:100:601f:14::a27d:90e
* IPv4: 162.125.9.14
* Trying [2620:100:601f:14::a27d:90e]:443...
* Trying 162.125.9.14:443...
* Connected to content.dropboxapi.com (162.125.9.14) port 443
* schannel: disabled automatic use of client certificate
* ALPN: curl offers http/1.1
* ALPN: server accepted http/1.1
* using HTTP/1.x
> PUT /2/files/upload HTTP/1.1^M
Host: content.dropboxapi.com^M
Accept: */*^M
Authorization: Bearer [my token]
Dropbox-API-Arg: {"path":"/WATCH/dummy.txt"}^M
Content-Type: application/octet-stream^M
Content-Length: 49^M
^M - * We are completely uploaded and fine
* schannel: remote party requests renegotiation
* schannel: renegotiating SSL/TLS connection
* schannel: SSL/TLS connection renegotiated
< HTTP/1.1 404 Not Found^M
< Content-Length: 1233^M
< Content-Type: text/html^M
< Date: Tue, 17 Dec 2024 01:18:46 GMT^M
< Server: envoy^M
< Strict-Transport-Security: max-age=31536000; includeSubDomains; preload^M
< X-Robots-Tag: noindex, nofollow, noimageindex^M
< Vary: Accept-Encoding^M
< X-Dropbox-Response-Origin: remote^M
< X-Dropbox-Request-Id: 4fe8d6981e85466fb0f0c353132e416c^M
< ^M
* Connection #0 to host content.dropboxapi.com left intact