This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to store files in session?  RSS feed

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

in my webapp I need to provide data in serveral formats for download: excel, xml and pdf. The question is: after I have generated these documents where do I store them? Should I save them on the local filesystem or is there a way to store the documents in the session?

cheers,

Pete
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If u have large chunks of information, I would recommend retrieving them fresh each time they need to print the report.

Saving large amount of data in your session doesnt seem wise unless you need it repetedly all over the application.
 
Pete Neu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree it's not good to keep the files longer than needed. But the point is how can I provide them just in time? First I do need to generate them and afterwards I need to provide a URL where the files are located on the filesystem. Is there any other way around this?
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Storing files in local file system isn't so bad idea, however you should consider the following:
1. cleanup files after usage or server crash.
2. keep files until persistent session keeps reference to them
3. share files in clustering configuration, when session can migrate from one to another box
 
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

First I do need to generate them and afterwards I need to provide a URL where the files are located on the filesystem. Is there any other way around this?


You could write the "file" to a ByteArrayOutputStream and save a reference to the final byte[] in the session. The servlet responding to the request for that URL would grab the byte[] and write it to the output stream.
Bill
 
Your mother was a hamster and your father was a tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!