Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does HTTP file upload work for large files?

I just want to elaborate this question: How does HTTP file upload work?. This is the form from the question:

<form enctype="multipart/form-data" action="http://localhost:3000/upload?upload_progress_id=12344" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

What happens when the file is really large (i.e. 10 GB)? Does the browser put all the data into 1 request then send it to the server? How does the browser read the file and build the request(s) when it has only 2 GB of RAM?

Let say the file is a CSV. Assuming the server has little RAM and Disk space. Is there a way to stream the file to the server so that the server can parse each line instead of keeping the whole file in its RAM or Disk?

Detailed explanations are much appreciated (HTTP, TCP, etc.)

like image 761
NXH Avatar asked Oct 10 '16 06:10

NXH


People also ask

How does HTTP transfer large files?

Send chunked data In version 1.1, HTTP introduced chunked data to help with the large-data cases. When sending a response, the server adds a header Transfer-Encoding: chunked , letting the browser know that data is transmitted in chunks.

How does HTTP upload work?

To upload data to a server, the client again initiates a connection to the server and then typically sends a HTTP POST request which contains the data to be uploaded. The server knows how to handle such a request and stores the data.

Which protocol is used to upload large files?

File Transfer Protocol (FTP) Server It allows you to safely and easily transfer multiple or large files over FTP and FTPS (that is, FTP over SSL/TLS), from mobile devices, as well as a web platform.


1 Answers

You can find some details here:

Large file upload though html form (more than 2 GB)

In a nutshell, the remote http server is what determines the maximum size of the HTTP POST. Anything larger than its configured maximum size, and you will receive an error.

Developing your own solution is an option. For your example of a large CSV file, imagine an HTTP POST that sends 1 line of the file. 100 lines would require 100 HTTP POSTs.

A major disadvantage is that an HTML form could not be used directly. Perhaps JavaScript could handle the posts for you, such as a variation of this post:

How to upload string as file with jQuery or other js framework

You would have some work to do on both sides if ordering is important (i.e. send some sort of sequence number as part of the form data).

There are other ways of accomplishing this. But hopefully the above suggestions will get you thinking.

like image 162
jmjatlanta Avatar answered Oct 14 '22 01:10

jmjatlanta