cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to know what we learned at IBC? Check out our learnings on media, remote working and more right here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

"Couldn't resolve host name" error

"Couldn't resolve host name" error

Borrow
New member | Level 2

I made app with visual studio 2015 and used libcurl.

 

but this shows error "Couldn't resolve host name"

 

CURL *curl;
CURLcode res;
std::string readBuffer;
 
// Your Dropbox access token
std::string accessToken = "****";
 
// File to upload
std::string filePath = "D://test.txt";
std::string fileName = "file.txt"; // Name of the file as it will appear in Dropbox
 
   // Open the file
std::ifstream file(filePath, std::ios::binary | std::ios::ate);
if (!file.is_open()) {
std::cerr << "Failed to open file." << std::endl;
return 1;
}
 
// Get file size
std::size_t fileSize = file.tellg();
file.seekg(0, std::ios::beg);
 
// Read the file into a buffer
char* fileBuffer = new char[fileSize];
file.read(fileBuffer, fileSize);
file.close();
 
// Set up the API request
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if (curl) {
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, ("Authorization: Bearer " + accessToken).c_str());
headers = curl_slist_append(headers, "Content-Type: application/octet-stream");
 
// Dropbox API specifics
std::string dropboxApiArg = "{\"path\":\"/" + fileName + "\",\"mode\":\"add\",\"autorename\":true,\"mute\":false}";
headers = curl_slist_append(headers, ("Dropbox-API-Arg: " + dropboxApiArg).c_str());
 
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, fileBuffer);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, fileSize);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
 
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
 
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
std::cerr << "cURL error: " << curl_easy_strerror(res) << std::endl;
}
else {
std::cout << "File uploaded successfully." << std::endl;
}
 
// Cleanup
curl_easy_cleanup(curl);
curl_slist_free_all(headers);
delete[] fileBuffer;
}
 
curl_global_cleanup();
 
return 0;
 
 
please help me
1 Reply 1

DB-Des
Dropbox Engineer

Hi @Borrow,

 

The "couldn't resolve hostname" error typically indicates an issue with DNS resolution rather than a problem with our API.

 

To troubleshoot this in your application, we would recommend verifying that the hostname is correctly specified in your code and checking the use of other functions. Additionally, ensure your network settings allow DNS queries and that there are no underlying connectivity issues.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    DB-Des Dropbox Engineer
What do Dropbox user levels mean?