nhatuan84 / esp32-upload-download-multipart-http

This library supports upload multipart and download file via http
25 stars 19 forks source link

File doesn't actually download to SD card -- file shows size 0 bytes #5

Open theotherjenkutler opened 2 years ago

theotherjenkutler commented 2 years ago

Hi I'm running a version of the example to just download a file over HTTP and it appears to be functioning normally except that the file that is downloaded onto the SD card shows 0 bytes. Any ideas? Thanks a million!

`#include "UDHttp.h"

include "mySD.h"

const char ssid = "ssid"; const char password = "pass";

File root; //these callbacks will be invoked to read and write data to sdcard //and process response //and showing progress int responsef(uint8_t *buffer, int len){ Serial.printf("%s\n", buffer); return 0; }

int rdataf(uint8_t *buffer, int len){ //read file to upload if (root.available()) { return root.read(buffer, len); } return 0; }

int wdataf(uint8_t *buffer, int len){ //write downloaded data to file return root.write(buffer, len); }

void progressf(int percent){ Serial.printf("%d\n", percent); }

void setup() { Serial.begin(115200);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }

Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP());

Serial.print("Initializing SD card..."); if (!SD.begin()) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); //SD.remove("audio.mp3"); { UDHttp udh; //open file on sdcard to write root = SD.open("audio.mp3", FILE_WRITE); if (!root) { Serial.println("can not open file!"); return; } //download the file from url udh.download("http://192.168.1.200/audio.mp3", wdataf, progressf); root.close(); Serial.printf("done downloading\n"); }

/ { UDHttp udh; //open file on sdcard to read root = SD.open("test.pdf"); if (!root) { Serial.println("can not open file!"); return; } //upload downloaded file to local server udh.upload("http://192.168.1.107:80/upload/upload.php", "test.pdf", root.size(), rdataf, progressf, responsef); root.close(); Serial.printf("done uploading\n"); } / }

void loop() { Serial.println("Test complete."); while(true){

}

}`

Almost forgot to mention -- I'm running it on a DOIT ESP32 DEVKIT V1 with Arduino v 2.0.2 and the mySD.h is from the esp32-micro-sd library located here: https://github.com/nhatuan84/esp32-micro-sdcard

not sure if this was the intended library but I didn't see any documentation about where that dependency should be found.

KK4HFJ commented 1 year ago

I can't figure out how you got 'File root;' to compile.