简体   繁体   中英

ASP.NET - Does streaming file to the client occupy server memory?

I have a requirement to make the files in a file server available for download through an application running on a web server. Users would be clicking on the links available on the application page and a save as dialog would appear. This kind of a use case is pretty common and I might be talking about a basic thing, but I would appreciate if someone can confirm if my following assumptions are correct.

1) With files on file server, virtually mapped via a virtual directory in the web server to be accessible to the application (as links), it is possible to stream it directly to the client using content-disposition (with code similar to the answer here ), meaning without involving any code to process or chunk the file for the purpose of streaming it.

2) Since the file is directly streamed from the file server, the web server is in NO WAY impacted in terms of memory or disk usage (CPU would be used of course).

Thanks

Since you want to write files directly and keep you memory footprint to a minimum, consider using HttpResponse.TransmitFile

Writes the specified file directly to an HTTP response output stream, without buffering it in memory.

This to my knowledge is the most efficient method to send a file in the response if you have to write it through asp.net.

Response.AppendHeader("Content-Disposition", "attachment; filename="+ fileName );
Response.TransmitFile(fullPath);
Response.Flush();
Response.End();

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