Passing a binary file(stream) to the presentation layer
-
Hi. I have a requirement to store files (they happen to be .pdf files but could be word/excel etc) on an application server. These files are to be requested from the presentation layer. When the user clicks a report, a reportid is passed to the middle tier, whereby it retrieves the associated filepath from the DB and then goes and loads the file. My problem is that I am not sure how to pass this file back to the presentation layer. What I would like to do, is spit out a stream to the response object so the file just opens in the users browser (rather than saving a copy on the web server and then allowing the user to either Open/Save). I thought a filestream or binaryreader object would do the trick, but if i pass this to the presentation layer, the second i call the .Read methods, ill get an exception as the file doesnt exist on the web server ! Can anybody suggest the best way(s) of achieving my goals ? Thanks.
-
Hi. I have a requirement to store files (they happen to be .pdf files but could be word/excel etc) on an application server. These files are to be requested from the presentation layer. When the user clicks a report, a reportid is passed to the middle tier, whereby it retrieves the associated filepath from the DB and then goes and loads the file. My problem is that I am not sure how to pass this file back to the presentation layer. What I would like to do, is spit out a stream to the response object so the file just opens in the users browser (rather than saving a copy on the web server and then allowing the user to either Open/Save). I thought a filestream or binaryreader object would do the trick, but if i pass this to the presentation layer, the second i call the .Read methods, ill get an exception as the file doesnt exist on the web server ! Can anybody suggest the best way(s) of achieving my goals ? Thanks.
You make no mention what your presentation layer is, however from the context I assume you mean a web page. If you set the Response.ContentType to the proper file type and use Response.OutputStream it should work.
-
You make no mention what your presentation layer is, however from the context I assume you mean a web page. If you set the Response.ContentType to the proper file type and use Response.OutputStream it should work.
Sorry, yes, an ASP.Net web page. Im am OK with sending the stream to the response object once ive got it...my problem is actually getting the stream object from the middletier in the first place. PresLayer - Requests doc id 1 AppLayer - Receives Request - Obtains the path of the file from the db - can open the file (filestream?) - RETURNS THE FILE/STREAM PresLayer - Spits stream out to response object. My question is how i can pass the binary data back from the applayer to the preslayer. Eg, surely if i pass the filestream back (as an out parameter for example), the minute i call .Read on the front end, ill get an exception because the file actually exists on another machine ?!
-
Sorry, yes, an ASP.Net web page. Im am OK with sending the stream to the response object once ive got it...my problem is actually getting the stream object from the middletier in the first place. PresLayer - Requests doc id 1 AppLayer - Receives Request - Obtains the path of the file from the db - can open the file (filestream?) - RETURNS THE FILE/STREAM PresLayer - Spits stream out to response object. My question is how i can pass the binary data back from the applayer to the preslayer. Eg, surely if i pass the filestream back (as an out parameter for example), the minute i call .Read on the front end, ill get an exception because the file actually exists on another machine ?!
Provided that permissions are set correctly you should be able to read the file into a stream and pass it to your presentation layer for display via Response.OutputStream
-
Provided that permissions are set correctly you should be able to read the file into a stream and pass it to your presentation layer for display via Response.OutputStream
y dunn u pass a byte array frm the Business Layer to the presentation layer? Read the contents in the business layer into a byte array and pass that array to the presentation layer and use ur logic to display the content.