Your workflow is unique 👨💻 - tell us how you use Dropbox here.
Forum Discussion
Mark L.45
1 year agoCollaborator | Level 9
Connecting a Seeed ESP32C3 to DropBox [Arduino]
I am trying to figure out how to upload a file on an ESP32C3 [which uses the Arduino IDE] to Dropbox. I am using the generic HTTP API as a basis for doing so. I am effectively converting "curl" com...
- 1 year ago
I figured out what I was doing wrong and posted the working code for the community's benefit.
void uploadFile() { Serial.println("Running Upload_file: "); HTTPClient http; File file = SD.open("/240x320.jpg"); if(!file) { Serial.println("Failed to open file for reading"); return; } int len = file.size(); char size[8]; sprintf(size, "%d", len); static uint8_t buff2[27142] = {255}; static unsigned char encoded[27142] = {255}; int x = file.read(buff2,len); unsigned int base64_length = encode_base64(buff2, len + 1, encoded); close(file); Serial.print("Size "); Serial.println(size); if (http.begin(dropbox_uploadfile)) { // HTTP String token_key = String("Bearer ") + dropbox_token; http.addHeader("Authorization", token_key); String args = "{\"autorename\":false,\"mode\":\"add\",\"mute\":false,\"path\":\"/Homework/math/Uploaded8.txt\",\"strict_conflict\":false}"; http.addHeader("Dropbox-API-Arg",args); String arg2 = "application/octet-stream"; http.addHeader("Content-Type",arg2); String wild = "The luck of the Irish"; int httpCode = http.POST((char*)encoded); String payload = http.getString(); Serial.print("payload: "); Serial.println(payload); http.end(); } }I posted an article on Medium with the download and list files commands, too, which you can find at this link. Yes, it's behind a paywall, but the first three articles are free.
https://medium.com/me/stats/post/1f755145f504
Greg-DB
Dropbox Community Moderator
1 year agoWhile I can't provide support for your HTTPClient class itself, from your description and code, it seems like the 'http.POST(args)' line POSTs the argument data into the request body, which is where the file data is supposed to go, so that becomes the uploaded file data. You may need to refer to the documentation for your HTTP client for more information on how to configure that to handle your use case.
Mark L.45
1 year agoCollaborator | Level 9
I figured out what I was doing wrong and posted the working code for the community's benefit.
void uploadFile() {
Serial.println("Running Upload_file: ");
HTTPClient http;
File file = SD.open("/240x320.jpg");
if(!file) {
Serial.println("Failed to open file for reading");
return;
}
int len = file.size();
char size[8];
sprintf(size, "%d", len);
static uint8_t buff2[27142] = {255};
static unsigned char encoded[27142] = {255};
int x = file.read(buff2,len);
unsigned int base64_length = encode_base64(buff2, len + 1, encoded);
close(file);
Serial.print("Size ");
Serial.println(size);
if (http.begin(dropbox_uploadfile)) { // HTTP
String token_key = String("Bearer ") + dropbox_token;
http.addHeader("Authorization", token_key);
String args = "{\"autorename\":false,\"mode\":\"add\",\"mute\":false,\"path\":\"/Homework/math/Uploaded8.txt\",\"strict_conflict\":false}";
http.addHeader("Dropbox-API-Arg",args);
String arg2 = "application/octet-stream";
http.addHeader("Content-Type",arg2);
String wild = "The luck of the Irish";
int httpCode = http.POST((char*)encoded);
String payload = http.getString();
Serial.print("payload: ");
Serial.println(payload);
http.end();
}
}
I posted an article on Medium with the download and list files commands, too, which you can find at this link. Yes, it's behind a paywall, but the first three articles are free.
https://medium.com/me/stats/post/1f755145f504
About Dropbox API Support and Feedback
Get help with the Dropbox API from fellow developers and experts.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!