Ravi Kiran Chanduri Updated date Nov 18, Convert Required file into Bytes Initially, we have to convert the file into bytes using File Class which is from System. Next Recommended Reading. Windows 10 Vs Windows Visual Studio Vs Visual Studio Getting Started With.
These methods are coming from the FileResult abstract class and gives you multiple options for retrieving files to send to the client. Here we will be returning an image from the Controller method.
Using the below technique controller can return any other types of images like. Here we will be returning a PDF file from the Controller method. Using the below technique controller can return any other types of file as well like. Here we will be returning or downloading an Excel file. Using the below technique Controller can return any other types of images like.
You cal also use the File class for file processing. Please see the below example to achieve the same. As we know FileResult is an abstract base class. Find centralized, trusted content and collaborate around the technologies you use most. Connect and share knowledge within a single location that is structured and easy to search. I have a big file of memory size 42 mb.
I want to download the file with less memory consumption. Controller Code. After checking in iis log, the download process is taking 42 mb and 64 mb each respectively. Thanks in advance. Your best bet is probably Response. TransmitFile then. I've used this on larger files GBs and had no issues before.
Writes the specified file directly to an HTTP response output stream, without buffering it in memory. Note, I've never run across a client browser, etc that didn't handle Transfer Encoding chunked.
You can read more at the link below. The key thing is to set Response. I think JanusPienaar's first solution should work with this. My MVC action is:. If RecordCount is , the file generated by TestApi is 1.
There is the Rizwan Ansari post that worked for me:. There are situation when you need to provide download option for a big file located somewhere on server or generated at runtime. Below function could be used to download files of any size.
So this function also handle this situation by breaking down file in 1 MB chunks can be customized by changing bufferSize variable. Saket: You'd have to write to an output stream. NET Core. Show 3 more comments. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Who owns this outage? Building intelligent escalation chains for modern SRE.
Podcast Who is building clouds for the independent developer? Featured on Meta. Now live: A fully responsive profile. Reducing the weight of our footer. Linked 2. Related
0コメント