Can't work with files on esp32

Posted on
  • I want to make a webserver using webserver module. I uploaded an html file via Espruino WEB IDE and wanted to reference it when creating a webserver, I did it in the following way:

    var code = require("Storage").readArrayBuffer('web.html');
    

    but when I start my server and browse the page, I see this message:

    WebServer error Error: Error: Could not open file : NO_PATH
    

    what did I do wrong?

  • I'm not sure you're using the code you have above. readArrayBuffer won't report back NO_PATH - that error comes from when you use the fs library with require("fs") (which is a FATFS filesystem)

  • I use storage library (4 line)


    1 Attachment

    • Снимок экрана 2024-11-15 165151.png
  • upd:
    I changed the information in 'memory' in var webs to '/' and got this error:

    WebServer error Error: Error: Could not open file : INVALID_NAME
    
  • That's from the FAT filesystem again. It's the WebServer module you're using: https://github.com/espruino/EspruinoDocs/blob/master/modules/WebServer.js#L188-L189

    Looks like when you init the webserver you need to be sure you specifically list your file:

        memory: {
            'web.html': { 
                'content': require("Storage").read('web.html'),
                'type': 'text/html'
            },
    

    See https://www.espruino.com/WebServer#how-to-use-the-webserver-module

  • ... or you can try copying the data into the FAT filesystem:

    require("fs").writeFileSync('web.html',  require("Storage").read('web.html'))
    

    At the moment the Web IDE doesn't have the ability to access/upload to the FAT filesystem directly as it's something that got added just for the ESP32

  • used this, still got error "INVALID_NAME". Btw I uploaded file by this function in the IDE


    1 Attachment

    • Снимок экрана 2024-11-15 213458.png
  • I figured out the problem, I had to name the file in memory index.html (I just started studying all this), thanks for the answers and help!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Can't work with files on esp32

Posted by Avatar for user159262 @user159262

Actions