These are chat archives for esp8266/Arduino

21st
Jul 2017
probonopd
@probonopd
Jul 21 2017 17:02
hi all, is there a way to make server.onFileUpload upload to a fixed filename (instead of using what the client sends)?
  server.onFileUpload([](AsyncWebServerRequest * request, const String & filename, size_t index, uint8_t *data, size_t len, bool final) {
    if(!index){
      // filename="cache.gco" ; // Override what the client sent as the filename - DOES NOT WORK
    }
  });
I am using ESPAsyncWebServer by @me-no-dev
Victor Tseng
@Palatis
Jul 21 2017 17:04
well that filename is the client tells you what file it sends
you get to decide where to store it.
for example user sends you C:\Users\Palatis\blah.jpg
and you can't modify it because it's a const String &.
probonopd
@probonopd
Jul 21 2017 17:08
i know that the client sends it, but I want to override what the client sends
and if i leave away the "const" then it doesn't compile
Victor Tseng
@Palatis
Jul 21 2017 17:09
you can't, that desicision is on the client.
probonopd
@probonopd
Jul 21 2017 17:09
well, the client sends a name but the server can certainly ignore what the client sends
or wait, could i move the file after it is uploaded?
Victor Tseng
@Palatis
Jul 21 2017 17:10
that filename is the filename from the client side
the file isn't saved anywhere
it's still in ram
read from data
probonopd
@probonopd
Jul 21 2017 17:10
the file is saved to spiffs
in a file with a name
and i want to override that name of the file on spiffs
Martin Ayotte
@martinayotte
Jul 21 2017 17:13
Simply not use the "filename" variable and provide another filename to SPIFFS calls.
Victor Tseng
@Palatis
Jul 21 2017 17:13
i guess not
i mean, the file isn't saved directly to SPIFFS.
at least not what's written in lib code.
Martin Ayotte
@martinayotte
Jul 21 2017 17:14
I understand that, it is up to user's code to call the SPIFFS functions
Victor Tseng
@Palatis
Jul 21 2017 17:14
i'm answering @probonopd XD
Martin Ayotte
@martinayotte
Jul 21 2017 17:14
:-)
Victor Tseng
@Palatis
Jul 21 2017 17:14
if you're using the default SPIFFSEditor class
it does write the file to a temp file
but if not (since you want to handle the write yourself), then it's not stored anywhere by default.
received data is in data provided by onUpload()
as i search through the lib code, the only place which calls a write() is inside SPIFFSEditor
Victor Tseng
@Palatis
Jul 21 2017 17:20
and the only place where SPIFFSEditor is used is inside example/ESP_AsyncFSBrowser
I guess you copy-pasted the example without modifying it to suite your needs.
probonopd
@probonopd
Jul 21 2017 17:25
I copy-pasted the example and now I want to change it so that it does what I need...
Victor Tseng
@Palatis
Jul 21 2017 17:25
yup, don't use that SPIFFSEditor, write your own handler.
cuz you want to do different things.
probonopd
@probonopd
Jul 21 2017 17:26
ok, thanks