简体   繁体   中英

HTML File upload server questions

I am trying to get a web page to upload a file to an embedded server. Some Googling has shown me how do the web page with a file picker and that works just fine.

The issue I am having is that I cannot get the browser to send anything other than the first POST packet which gives the file name and, looking at the TCP data, the first few bytes of the files it is sending. However, even though I've tried ending an HTTP OK and an HTTP No data return, no further data comes from the browser.

I have used this HTML:

<form action='' method='POST' enctype='multipart/form-data'> \
    <input type='file' name='userFile'><br> \
    <input type='submit' name='upload_btn' value='upload'> \
</form>

This, sure enough, sends a TCP POST packet with a load of information like filename=, the encoding type and eventually what looks like he first few lines of the file itself.

Exactly what I've tried having the embedded server send back is:

"HTTP/1.1 200 OK\\r\\nContent-type: text/html\\r\\n\\r\\n"

Or

"HTTP/1.1 204 No Content\\r\\n"

Neither persuades the browser to send the next chunk of the file to the server. Can anyone advise what I am doing wrong please?

Many thanks.

Ah, to answer my own question, in the unlikely hope that it helps someone else, the problem was that I was closing the connection. I was forgetting that it's not like a normal transaction where you send the information then close the socket. If I keep the socket open and just continue to listen to what is coming in, the browser continues to send out the rest of the file. Important, I think, to monitor exactly what's coming in, the size of the file being sent and then close the socket once all that information is received.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM