Browser won't send upload file if enctype="text/plain"

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
liudr
Posts: 211
Joined: Tue Oct 17, 2017 5:18 am

Browser won't send upload file if enctype="text/plain"

Post by liudr » Sat Nov 27, 2021 4:30 am

I'm making a web server on my ESP32 MP board so it will accept file uploads, simple text-only files as config files. Sounds great! I couldn't find examples so I started to hammer out my own code.

I got a web page with a form to upload. And my browser only sends the file to my ESP32 if I choose enctype="multipart/form-data" with post method. I wonder why it won't send the file if I use enctype="text/plain". Is that what browsers all do?

Code: Select all

    <form action="" method="post" enctype="multipart/form-data">
        <input type="hidden" name="MAX_FILE_SIZE" value="100000">
        <input type="file" id="myFile" name="filename" class="button" accept=".conf">
        <input type="submit" value="Upload" class="button button3">
    </form>
Anyway, this creates more processing needs for ESP32 because it needs to identify the boundaries etc. and extract file content. I wish it just sends the content right after the header with a Content-Length header indicating the length. Is that doable with a browser or should I just use PC Python code as as client to send the files this easy way?

Thanks!

Post Reply