简体   繁体   English

HTML文件上传服务器问题

[英]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. 我遇到的问题是,我无法让浏览器发送除第一个POST数据包以外的任何内容,第一个POST数据包提供了文件名,并且在查看TCP数据时,发送的是文件的前几个字节。 However, even though I've tried ending an HTTP OK and an HTTP No data return, no further data comes from the browser. 但是,即使我尝试结束HTTP OK和HTTP No数据返回,也不会从浏览器获得更多数据。

I have used this HTML: 我使用了以下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. 这肯定会发送一个TCP POST数据包,其中包含诸如filename =,编码类型以及最终看起来像文件本身的前几行之类的信息。

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" “ HTTP / 1.1 200 OK \\ r \\ n内容类型:text / html \\ r \\ n \\ r \\ n”

Or 要么

"HTTP/1.1 204 No Content\\r\\n" “ 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. 我认为,重要的是要准确地监视即将进入的内容,正在发送的文件的大小,然后在收到所有这些信息后关闭套接字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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