I have a web application in which the user can configure reports (ASP.NET MVC, no Reporting Services or anything). The configuration is then represented as a JavaScript object which is sent to the server as JSON to retrieve data and actually generate the report. The submission HTML look similar to this:
<form method="post" action="/RenderReport" target="_blank">
<input type="hidden" name="reportJson"/>
</form>
This works very well for opening the report in a new browser window. However, in this report, I want to include images that are genetated from the data. How can this be done in a good way? The obvious ways that come to mind are:
- Embed the metadata necessary to generate the images in the URL, like
<img src="/GenerateImage/?metadata1=2&metadata2=4"/>
. This won't work, however, since the metadata is very likely to make the URL exceed the 2083 characters max in IE. - Use an ajax POST request, and then when the response comes back, create an image element like
<img src="data:image/png;base64,{data_in_json_response}"/>
. This is not possible, though, since my application has to work in IE6, which doesn't support data URIs. Generate the images while generating the report, creating a unique key for each image, and then use URLs of the form
<img src="/GetCachedImage?id=23497abc289"/>
. This is my current best idea, but it does raise the issue of where to cache the images. The places I can think of are:- In the session. Advantage: The cached item is automatically deleted when when the session is abandoned. Disadvantage: accessing the session will serialize accesses to the page within a session. This is bad in my case.
- In the database: Advantage: Works well. Disadvantage: Unnecessary overhead, the cached items must be deleted some time.
- In the Application / Cache object. I haven't really thought through all advantages and disadvantages of this one.
It also raises the question of when to delete the cached items. If I delete them right after the image is shown, it seems that the page can't be refreshed or printed without the images becoming red xes. Every other option means extra complexity.
How can this problem be solved in a good way, or at least one that isn't bad?