Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do file upload streams get the content from?

I have a question regarding file upload, which is more related to how it works rather than a code issue. I looked on the internet, but I couldn't find a proper answer.

I have a web application running on tomcat, which handles file uploads (through a servlet). Let's say I want now to upload huge files (> 1 Gb). My understading was that the multipart content of the HTTP request was available in my servlet once the whole file was actually transfered.

My question is where the content of the request is actually stored ? When one calls HttpServletRequest.getParts() an InputStream is available on the Part object. However, where is the stream reading from ? Does Tomcat store it somewhere ?

I guess this might not be clear enough, so I'll update the post according to your comments, if any.

Thanks

like image 772
benjamin.d Avatar asked Nov 27 '13 12:11

benjamin.d


People also ask

How are files uploaded to server?

The commonly way to upload data to the server is using FTP client. FTP (File Transfer Protocol) is used to transfer data from one computer (your personal computer) to another computer (webserver). FTP client looks like File Manager and you can copy (upload, download) files here from one computer to another computer.

Where does uploaded files go?

Uploaded files are saved to the /files directory.

How are files uploaded?

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.

What is upload content?

Share: Uploading is the process of moving digital files such as photographs or documents from your computer and placing them on to a central server so that someone else can retrieve them or to a website so others can see them.


1 Answers

Tomcat stores Parts in "X:\some\path\Tomcat 7.0\temp" (/some/path/apache-tomcat-7.0.x/temp) directory.

when a multipart request is parsed, if the size of a single part exceed a threshold, a temporary file is created for that part.

your servlet/jsp will be invoked when transfer of all parts has been completed.

when the request is destroyed all temporary files are deleted as well.

if you are interested in the multipart parse phase, take a look at apache commons-fileupload (specifically ServletFileUpload.parseRequest()), tomcat is based on a variant of that

UPDATE

you can configure it as a java arg, ie in windows:

enter image description here

like image 104
Michele Mariotti Avatar answered Sep 20 '22 07:09

Michele Mariotti