-->
Page 1 of 5

Good demo for uploading a file to spiffs from browser?

PostPosted: Thu Oct 01, 2015 8:00 pm
by Mmiscool
I am working on making it so that can upload files from the browser in to the spiffs file system.

Are there any examples out there s to how to do it.

Been searching the forum for about 20 minuets and have not found any thing that is clear to me.

Re: Good demo for uploading a file to spiffs from browser?

PostPosted: Mon Oct 12, 2015 9:48 pm
by Mmiscool
Bump.

Still looking for an example sketch.

Re: Good demo for uploading a file to spiffs from browser?

PostPosted: Tue Oct 13, 2015 4:04 pm
by martinayotte
You can look at the example libraries/ESP8266WebServer/examples/WebUpdate/WebUpdate.ino, and change it a bit to call SPIFFS open/write/close in the server.onFileUpload callback instead of the Update.begin/write/end.
It should be pretty straight forward...

Re: Good demo for uploading a file to spiffs from browser?

PostPosted: Tue Oct 13, 2015 8:11 pm
by Mmiscool
Whiddled it down to the following code.

Any help is appreciated.

Don't exactly get whats going on.

Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include "spiffs/spiffs.h"
#include <FS.h>


const char* ssid = "........";
const char* password = "........";

ESP8266WebServer server(80);
const char* serverIndex = "<form method='POST' action='/update' enctype='multipart/form-data'><input type='file' name='update'><input type='submit' value='Update'></form>";

void setup(void)
{
  SPIFFS.begin();
  Serial.begin(9600);
  WiFi.mode(WIFI_AP_STA);
  WiFi.begin(ssid, password);
  if (WiFi.waitForConnectResult() == WL_CONNECTED)
  {
    server.on("/", HTTP_GET, []() {
      server.sendHeader("Connection", "close");
      server.sendHeader("Access-Control-Allow-Origin", "*");
      server.send(200, "text/html", serverIndex);
    });
    server.onFileUpload([]() {
      //if (server.uri() != "/update") return;
      HTTPUpload& upload = server.upload();

      String Test = upload.filename.c_str();
      File f = SPIFFS.open(String("/" + Test ), "w");
      f.print(upload.buf);
      f.close();
      yield();
    });
    server.on("/update", HTTP_POST, []() {
      server.sendHeader("Connection", "close");
      server.sendHeader("Access-Control-Allow-Origin", "*");
      server.send(200, "text/plain", "OK");
      ESP.restart();
    });
    server.begin();
  }
}

void loop(void) {
  server.handleClient();
  delay(0);
}


I get the following error msg.
Code: Select allIn file included from dfgdfgdfgdfg.ino:11:0:
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/FS.h:112:11: error: 'FS' is already declared in this scope
 using fs::FS;
           ^
dfgdfgdfgdfg.ino: In lambda function:
dfgdfgdfgdfg:37: error: call of overloaded 'print(uint8_t [2048])' is ambiguous
dfgdfgdfgdfg.ino:37:25: note: candidates are:
In file included from C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/Stream.h:26:0,
                 from C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/HardwareSerial.h:32,
                 from C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/Arduino.h:247,
                 from C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\libraries\ESP8266WiFi\src/WiFiClient.h:24,
                 from C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\libraries\ESP8266WiFi\src/ESP8266WiFi.h:32,
                 from dfgdfgdfgdfg.ino:5:
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/Print.h:68:16: note: size_t Print::print(const String&) <near match>
         size_t print(const String &);
                ^
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/Print.h:68:16: note:   no known conversion for argument 1 from 'uint8_t [2048] {aka unsigned char [2048]}' to 'const String&'
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/Print.h:69:16: note: size_t Print::print(const char*) <near match>
         size_t print(const char[]);
                ^
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/Print.h:69:16: note:   no known conversion for argument 1 from 'uint8_t [2048] {aka unsigned char [2048]}' to 'const char*'
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/Print.h:70:16: note: size_t Print::print(char) <near match>
         size_t print(char);
                ^
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/Print.h:70:16: note:   no known conversion for argument 1 from 'uint8_t [2048] {aka unsigned char [2048]}' to 'char'
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/Print.h:71:16: note: size_t Print::print(unsigned char, int) <near match>
         size_t print(unsigned char, int = DEC);
                ^
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/Print.h:71:16: note:   no known conversion for argument 1 from 'uint8_t [2048] {aka unsigned char [2048]}' to 'unsigned char'
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/Print.h:72:16: note: size_t Print::print(int, int) <near match>
         size_t print(int, int = DEC);
                ^
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/Print.h:72:16: note:   no known conversion for argument 1 from 'uint8_t [2048] {aka unsigned char [2048]}' to 'int'
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/Print.h:73:16: note: size_t Print::print(unsigned int, int) <near match>
         size_t print(unsigned int, int = DEC);
                ^
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/Print.h:73:16: note:   no known conversion for argument 1 from 'uint8_t [2048] {aka unsigned char [2048]}' to 'unsigned int'
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/Print.h:74:16: note: size_t Print::print(long int, int) <near match>
         size_t print(long, int = DEC);
                ^
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/Print.h:74:16: note:   no known conversion for argument 1 from 'uint8_t [2048] {aka unsigned char [2048]}' to 'long int'
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/Print.h:75:16: note: size_t Print::print(long unsigned int, int) <near match>
         size_t print(unsigned long, int = DEC);
                ^
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\cores\esp8266/Print.h:75:16: note:   no known conversion for argument 1 from 'uint8_t [2048] {aka unsigned char [2048]}' to 'long unsigned int'
call of overloaded 'print(uint8_t [2048])' is ambiguous