• @Wilberforce
    Were you ever able to to upload files to your espruino with the pipe?

    I am following your example, but I am not seeing the complete file save in the flash.

    File index.htm size is 4752, printed POST data is "cRcv": 4752, but file in flash does not match.

    I know that the problem is not in the filesystem, because using "multipart/form-data" on the form post I get the complete file... plus some added strings like this:

    ------WebKitFormBoundaryZ2Lus84JA68itxnM
    Content-Disposition: form-data; name="file"; filename="index.html"
    Content-Type: text/html

    ...html file contents...

    ------WebKitFormBoundaryZ2Lus84JA68itxnM--

    httpSRq: { "type": 1,
      "res": httpSRs: {  },
      "svr": httpSrv: { "type": 1,
        "#onconnect": function (b,d) {if(b.headers.Connection&&0<=b.headers.Connection.indexOf("Upgrade")){var f=b.headers["Sec-WebSocket-Key"];f=btoa(E.toString(require("crypto").SHA1(f+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11")));d.writeHead(101,{Upgrade:"websocket",Connection:"Upgrade","Sec-WebSocket-Accept":f,"Sec-WebSocket-Protocol":b.headers["Sec-WebSocket-Protocol"]});var g=new e(void 0,{masking:!1,connected:!0});g.socket=d;b.on("data",g.parseData.bind(g));b.on("close",function(){clearInterval(g.srvPing);g.srvPing=void 0;g.emit("close")});
    g.srvPing=setInterval(function(){g.emit("ping",!0);g.send("ping",137)},g.keepAlive);c.emit("websocket",g)}else a(b,d)},
        "#onwebsocket": function (ws) {print(ws);
            ws.on('message', msg => { print("[WS] " + JSON.stringify(msg)); });
            ws.on('close', evt => { print("[WS] CLOSED"); });},
        "port": 80, "sckt": 4098 },
      "sckt": 4099,
      "headers": {
        "Host": "192.168.25.8",
        "Connection": "keep-alive",
        "Content-Length": "4752",
        "Origin": "http://192.168.25.8",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.53 Safari/537.36",
        "DNT": "1",
        "Accept": "*/*",
        "Referer": "http://192.168.25.8/upload",
        "Accept-Encoding": "gzip, deflate",
        "Accept-Language": "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7,it;q=0.6,ja;q=0.5,es;q=0.4"
       },
      "cRcv": 4752,
      "method": "PUT",
      "url": "/upload",
      "hdrs": true,
      "dRcv": ""
     }
    
    >fs.statSync("upload")
    ={ "size": 3216, "dir": false,
      "mtime": Date: Mon Feb 1 2077 00:00:00 GMT+0000
     }
    
            if (a.pathname == "/upload") {
                print(req);
                if (req.method == "PUT") {
                    try {
                      fs.unlink(a.pathname);
                    }
                    catch (e) { }
                    var f = E.openFile(a.pathname, "w");
                    req.pipe(f, {
                        chunkSize: 512, end: false,
                        complete: () => {
                            f.close();
                            res.end();
                        }
                    });
                }
                else {
                    res.writeHead(200, {'Content-Type':'text/html'});
                    res.end(html_index);
                }
            }
    
About

Avatar for barbiani @barbiani started