Jquery post request download file
This example sends an HttpGet request, and thus the data payload just one record ID in the request is included as parameters in the URL. But, what if I wanted to send an HttpPost request, with the data payload included as an object containing many fields in the request?
Gedao Gedao 1, 9 9 silver badges 13 13 bronze badges. Is it easier for you to pass model id to the action and then find your student by id and do whatever you want with student model data. I have updated the answer. There's no dual access to DownloadAttachment method?
This will call DownloadAttachment method 2 times. How to avoid that? There is absolutely no need to use ajax for this at all. Just call window. All this is doing is making the same request twice. I have no idea why this was upvoted. Show 4 more comments. Equals Constants. Combine Path. Message ; return Content e. GetExtension path. Raw Localizer["Report has been exported successfully"]. ReadAllBytes file1. FullName ; return File fileBytes, System.
Dilshad Dilshad 1 1 1 bronze badge. No support for download attribute on IE and Safari : caniuse. You can open a new window and put content there, but not sure about a PDF or Excel You should free up browser memory after calling click : window. JoshBerke This is old but it works on my end. How can I get it to open up my directory immediately to save rather than saving to my browser?
Also is there a way to determine the name of the incoming file? It will corrupt binary files, because they get converted to strings using encoding, and result is not very close to original binary May use mimetypes to not corrupt the information as used here with PDFs: alexhadik.
Data; formGenerate. Al though, there are few alternatives but they are not perfect and won't work on all browsers: Look at data URI scheme. If binary data is small then you can perhaps use javascript to open window passing data in URI. VinayC VinayC It looks like that may be the only way to do it in a single request. But it isn't really the direction I want to go.
I'd used URI data for thumbnails before, but it never occurred to me to use it for downloads - thanks for sharing this nugget. MapPath string. ReadAllText path ; System. Frank Frank 3, 1 1 gold badge 24 24 silver badges 36 36 bronze badges. I think I like this solution best. In my case though I am generating the file, so I think that I will try keeping the file in memory until it is accessed and then free up the memory after it's downloaded so I never have to write to disk.
I like this solution. In the OP's question it sounds like the requester knows whether to expect a file download or JSON data, so he could decide at the client end and post to a different URL, rather than deciding on the server end. My second approach is looking more appealing to me now too.
Thanks for confirming it is a worthwhile solution. Are you suggesting that I pass an additional value in the json object that indicates this request is being made from a browser as an ajax call instead of a web service call? There are several ways to accomplish this that I can think of, but what technique you would use? Or any other http header? Otis-iDev Otis-iDev 61 4 4 bronze badges. This will work, for small files. But if you have a large file you are going to run into the problem of the url being too long.
Try it with 1, records, it will break and only export part of the data. Found it somewhere long time ago and it works perfectly! Den Nikitin Den Nikitin 19 7 7 bronze badges. Wray Smallwood Wray Smallwood 87 3 3 bronze badges. Solution Content-Disposition attachment seems to work for me: self.
Mr-Programs Mr-Programs 4 4 silver badges 20 20 bronze badges. What could be wrong with this? What is an Event-Sourcing? If you will remember back to the early s when one click spun off pop ups. Ryan Guild Ryan Guild 1 1 1 bronze badge. Daniel Daniel 2, 21 21 silver badges 18 18 bronze badges.
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. This comment has been minimized. Sign in to view. Copy link Quote reply. This works a treat, Thanks! Thanks man, I was looking for days This is phenomenal. Thanks for sharing. Thanks for sharing, it is working. Very helpfull. Just amazing, thank you very much! Server returned error Just found today a very simple solution window. Thanks, man, you saved the day! Sign up for free to join this conversation on GitHub. Already have an account?
Sign in to comment. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window.
0コメント