Operation of Request.Files;

Asked

Viewed 777 times

2

I have an Asp . Net MVC project, with a form on View which sends files to the Controller.

In control I recover the files as follows:

var myFiles = Request.Files;

Not saving the file, just reading the content.

The question is, where are these files from Request.Files? In memory or some temporary folder on the server?

Imagine the following scenario:

100 users sending at the same time 10 100MB files each, all this will be allocated in memory?

I believe this can greatly impair the performance of my server, am I right? Is there any way around the problem?

  • Limit upload?

  • Thank you @LINQ , but even so this would not limit the amount of users simultaneously sending a small amount of files. Still I would have a problem, but what has caused me doubt is where are those files obtained through the Request.Files, because maybe I could think a little better with the answer.

  • Well, chances are they’ll stay in the memory, along with all the other information about the request. Recording on disk to recover later seems more damaging than having it in memory to do whatever it takes. If you need many uploads and they are large files, you will need a server that can handle this. If you are afraid that someone will make a "joke" and end up disturbing the work of the server, you will need a way to block it. Anyway, I’m not sure about that and I can’t see right now, it’s more of a guess anyway.

  • Thanks again @LINQ , I also assume that the files are only in memory, but I would like to be more sure of that. I’m trying to find something in the documentation, but unsuccessful for now.

1 answer

2


According to this Microsoft documentation the files nay are saved directly to the server memory (depending on some criteria).

Files are uploaded in MIME Multipart/form-data format. By default, all requests, including form Fields and uploaded files, Larger than 256 KB are buffered to disk, rather than Held in server memory.

Free Translation: The files are loaded in Multipart/form-data MIME format. By standard, all orders including form fields and files loaded, larger than 256 KB are buffered on disk, in instead of being stored in the server memory.

After the request is finished, the files uploaded to the server are destroyed, which causes us to use the method Saveas if we want a durable hard copy.

It is possible to specify in the Web.config some properties that change the amount of data that will be stored in buffer, the Requestlengthdiskthreshold, but do not forget also the Maxrequestlength to avoid denial of service attacks of some smart guys who want to post very large files.

More about Buffer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.