A custom ActionResult for a multi-part http response?


A custom ActionResult for a multi-part http response?



I'd like to respond to an http request with both a txt file and an html page. This way the client can save the file and see a summary of that file's contents via an html page.

Since the file is generated on the fly, I have to use state management on the server to generate the summary on the second request. I'd like to avoid this and wrap this up in a single response.

What would the custom ActionResult look like?




POSTing data programatically

1:



Modify HttpServletRequest body


2:


You could send XML with reference to an XSLT stylesheet.

The browser can do the transformation and display a resulting HTML output.. And the user may simple do "File->Save as ..." to store the XML file..


3:


Why not render the summary as normal HTML View and provide a link under that summary that points to a separate ActionResult that returns binary data....
public ActionResult SendFile(int id)     {         File file = FileRepository.GetFile(id);         byte[] fileData = file.FileData.ToArray();         return File(fileData, file.FileMimeType, file.FileName);     } 


4:


I did some search on this topic and to my surprise, this seems people did this already.

I found a description here, but it does not provide a public test URI, so I couldn't test browser behaviour on this.

It also mentiones the solution to send an archive file to the client.

But I assume that's not what you're looking for, right?. Here is another article showing an example with multipart responses.

Sadly, the demo URI seems not to be working any more.. So the situation is this: HTTP multipart responses can be done.

There are client (few) libraries to handle those in application code.

Browser behaviour is to be tested (Here's a voice).

Using this feature seems experimental and may be recommended only you can control both ends of the communication to eliminate interoperability issues..



94 out of 100 based on 44 user ratings 394 reviews