-->
Page 1 of 1

Downloading files to SPIFFS examples?

PostPosted: Tue Jan 31, 2017 7:59 pm
by seedseifer
Hello,

someone have an example for download files (png, txt, bin etc) from http server and store them on SPIFFS?

Cannot find an example for that, only storing html results for simple "get" like the part of code bellow:

while(client.available()) {
line = client.readStringUntil('\r');
line.trim();

thks

Re: Downloading files to SPIFFS examples?

PostPosted: Tue Jan 31, 2017 8:11 pm
by gdsports
Example program that reads data from an http server and sends the data out the serial port. It could be modified to write the data to a SPIFFs file instead.

https://github.com/esp8266/Arduino/blob ... Client.ino

Re: Downloading files to SPIFFS examples?

PostPosted: Fri Sep 07, 2018 10:53 am
by Erol444
I got it working like this :)
Code: Select all    String url = String(UPDATE_URL) + response.substring(4);
    //url = http://123.123.123.123/SPIFFS/test2.htm
    String file_name=response.substring(response.lastIndexOf('/'));
    //file_name = test2.htm
    Serial.println(url);
    File f = SPIFFS.open(file_name, "w");
    if (f) {
      http.begin(url);
      int httpCode = http.GET();
      if (httpCode > 0) {
        if (httpCode == HTTP_CODE_OK) {
          http.writeToStream(&f);
        }
      } else {
        Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
      }
      f.close();
    }
    http.end();