Event sourcing has a bunch of meanings across computing such as a system of pub sub in a cloud based architecture, or the browser api EventSource. In the context of a browser all events have a source and that source has hidden property that says who initiated this event the user or the site.
No, of course you can. You just need to give the user a chance to create the event. Here are a number of patterns that you can use to create user flows that are obvious and convectional and will not be flagged as fraud. Preloading If your download is non-configurable you may want to consider preloading the download into resp. As with the other answers you can use window. Ahh but I'm just a hobbiest who loves his garbage collector.
Have no fear this is very simple if you are working in most frameworks for me react you just register some sort of clean up effect on your component and your right as rain. I think I got close, but something is corrupting the file Image , any way, maybe some one can disclose the problem of this approach.
With HTML5, you can just create an anchor and click on it. There is no need to add it to the document as a child. If you want to have a special name for the download, just pass it in the download attribute:. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 11 years, 3 months ago. Active 4 months ago. Viewed k times. There must be a simpler way to accomplish this. Any other ways to accomplish this? Tauren Tauren Put the header in php file. No need to send any ajax or get requests — abhishek bagul. Add a comment. Active Oldest Votes. SamStephens SamStephens 5, 6 6 gold badges 33 33 silver badges 44 44 bronze badges. Then it also warns me the file may be dangerous.
If I visit the retData. Looking around the internet, it looks like you can have issues with PDFs in iFrames if your server is not setting Content-Type and Content-Disposition properly. I haven't actually used this solution myself, just clarified a previous solution, so don't have any other advice I'm afraid. Tauren: If you agree that this is a better answer, note that you can switch the accepted answer at any time - or even remove the accept mark entirely.
Simply check off the new answer and the accept mark will be transferred. Old question, but it was brought up in flags recently. Show 4 more comments. Jason Williams 2, 25 25 silver badges 34 34 bronze badges.
JoshBerke JoshBerke 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. The more I think about it, the more I like the last option. This way I can get information back about the request time to generate, size of file, error messages, etc.
The downside is extra file management on the server. This will wipe out any event bindings your page has, amongst other things. Create an element and use appendChild instead. Adding an iframe to the page that references that URL will result in the browser promoting the user to download the file, assuming that the web server has the appropriate mime type configuration.
It will only download the file in Chrome, Firefox and Opera. This uses a download attribute on the anchor tag to force the browser to download it. I know this kind of old, but I think I have come up with a more elegant solution.
I had the exact same problem. The issue I was having with the solutions suggested were that they all required the file being saved on the server, but I did not want to save the files on the server, because it introduced other problems security: the file could then be accessed by non-authenticated users, cleanup: how and when do you get rid of the files.
And like you, my data was complex, nested JSON objects that would be hard to put into a form. What I did was create two server functions. The first validated the data. If there was an error, it would be returned. Then, on the client, I have a form that has only one hidden input and posts to a second server function. I set the hidden input to the base64 string and submit the format. The form could submit to a new window or an iframe on the page and the file will open up.
In short, there is no simpler way. You need to make another server request to show PDF file. It is been a while since this question was asked but I had the same challenge and want to share my solution. Instead of saving the file between the requests, it saves the post data. It seems to be both simple and effective. I think the best approach is to use a combination, Your second approach seems to be an elegant solution where browsers are involved.
So depending on the how the call is made. Not entirely an answer to the original post, but a quick and dirty solution for posting a json-object to the server and dynamically generating a download.
I have been awake for two days now trying to figure out how to download a file using jquery with ajax call. All the support i got could not help my situation until i try this. Another approach instead of saving the file on the server and retrieving it, is to use. NET 4. The reason that I want to use JQuery Ajax to do the call, is that it is asynchronous.
Building my dynamic PDF file takes quite a bit of time, and I display a busy spinner dialog during that time it also allows other work to be done. It depends on the content of the PDF file.
0コメント