I am using ASP.NET 4.0 + IIS 7 to serve up a number of large PDFs via Response.TransmitFile.
The PDFs are all linearized, i.e. "Fast Web View". However the browser still requires the entire PDF to be downloaded before displaying any of it. All I want to do is show the first page (at least) without having to wait several minutes for the entire PDF to download.
From what I have read, the response header should include ["Accept-Ranges", "bytes"] but this does not seem to help.
Can anyone give me some pointers?
Thanks in advance!
I don't think you can do that easily. For byte range to work you would need many requests to serve the same file. How would you associate all these requests with a single file instance? You would probaly need to save the file to disk or somehonw maintain the file in memory... it could get tricky...
Much simpler would be to save PDFs in a shared folder (a first in first out cache) and let the HTTP 1.1 do the rest.
Related
My application currently allows direct links to PDF files on the server, but the files now need to be secured and direct links will have to be phased out because of security concerns.
I have tried the following lines to send PDF file to the client. It works fine.
Response.Clear();
Response.ContentType = "Application/pdf";
Response.WriteFile(filepath);
Response.End();
But there is a catch.
When a PDF file is linked, the browser renders the first few pages right away while downloading the rest. But with the approach above, the browser waits until the entire file has been downloaded and then proceeds to render the PDF.
So is there a way to trick the browser into mimicking opening a directly linked PDF?
After reading your post I realized my application had the same behavior (although given the typical sizes of files and the formats used it hasn't been an issue - at least not yet...) Upon some research, you'll have to choose from a couple of options depending upon how much complexity you want to introduce:
If you want a simpler implementation, you'll need to change your approach a bit to set up a loop that reads a certain amount of the file into a buffer in memory and then performs a Response.Write for that buffer. In the loop you'd then do a Response.Flush to push that data towards the client. Since this is synchronous, you'll have to wait until the flush is complete before you can push down the next block of the file. But, if the primary goal is getting the first couple of blocks out there so they client application can begin working with them, this might meet your needs.
If you want potentially better server-side scalability and are willing to accept a bit more complexity, you'll need to explore using Response.BeginFlush. I believe asynchronous writing was introduced in .Net 4.5. Here's a link that should get you started:
http://www.slideshare.net/pragyanshis/asynchronous-reading-and-writing-http-r-equest
I'm adding exploring both approaches to my "to do" list for my own application...
User need to upload 30,000 csv values, these values may contain 16 digit numbers or zipcodes.
Now our asp.net project doesn't use AJAX tool kit controls or jquery or any other 3rd party controls or open source code. This is restriction as per companies privacy policy.
So I have to come with a best way to accommodate file upload feature. This has to be versatile in regards to re-usability some thing like a custom control
This file upload feature should not be saved on the server, instead I need to read data into stream buffer and send them to UI then once user verify these values he/she'll have to hit submit thus values will be saved to DB.
what are the best ways to implement this,
Can I make use of System.Net.Webclient? or
Is there any other alternative ways by using Async HttpHandlers?
Can I show file upload progress to UI ?
Appreciate if you could help me with proper guidence on this.
Thanks in advance
krish
Well 30,000 values of zipcode or any other 16 digit code should be uploadable normally using file control(i mean via postback).
if you have to read and show 30,000 on the UI, i presume you are at risk of freezing your UI.
Moreover if you are not on HTML5, there is no way that you can read the content on the client side, except if you fiddle around with flash.
HTML 5 file api reference
http://www.html5rocks.com/en/tutorials/file/filesystem/
How to read and write files with Flash(Action script)
http://www.mikechambers.com/blog/2008/08/20/reading-and-writing-local-files-in-flash-player-10/
Recently I was approached to develop an application (asp.net/c#) to allow users to listen some audio files stored in some shared folders.
The users didn't have access to the shared folders, and the files should be streamed. Also, the page should provide the play/stop/pause/forward/back functions, as well as time elapsed/total time information.
So I setup a webservice that access the required file, and return a Byte[] containing the mp3/wav audio (actually I have to convert them to the desired mp3/wav format prior to returning the Byte[]).
The problem is that I have no idea on how to present it in the webpage.
What i need is a webpage with some control that provides the necessary functionalities and information, loaded from a Byte[].
I've researched the web and tried a lot of snippets and controls with no luck at all.
Any ideas or directions on how to implement it?
Thanks in Advance,
António
You could use HTML5's audio tag, if you expect your users to be using fairly recent browser versions. You'd set the src to a URL that would be set up to write your byte[] to the response stream (e.g. maybe store the byte[] in Session, make an .ashx handler page to return that, and set src="myHandler.ashx").
A good approach would be to use silverlight or flash player, even a java applet.
How to measure upload and download internet speed with silverlight and ASP.NET MVC between client and server.
How I think it's need to download/upload a file on the server.
Please help me with this problem
Thanks in advance
Sounds like you are trying to recreate SpeedTest.net. They use Flash, but the concepts should be roughly the same.
If you're referring to ASP.NET MVC because the Silverlight app is hosted on it, I'm not sure it will impact your design. This assumes that all the speed testing logic and UI is implemented in the Silverlight application.
Here's a good article from Laurent Bugnion on downloading files using WebClient:
http://www.galasoft.ch/mydotnet/articles/article-2008032301.html
That should give you all the information you need to download the file to the client, display a progress bar, and be notified when the download is complete. Using a fixed-size dummy data file, you can easily calculate the speed based on the size and time to download. The file should be fairly large but not too large, say 10 - 15Mb. That will ensure an accurate estimate of speed for both slow and very fast connections.
Uploading will work the same way in reverse. KrystalWare's SlickUpload component should have all the features you need.
The quick and dirty way to do it is just transfer a file to the client and have it send it back.
What you will need to do is have a file of known size, download it to the client, take the filesize/time to transfer and that is your download speed. Do the reverse process to get the upload speed.
It is a good idea to have a file at least a few MB in size so it can average out the peeks and valleys in the transfer.
You realize, of course, that the results of your test will be completely dependent on the internet connection that you are using to run the test. From what I am reading, your really just testing your internet connection, which you can do on various websites, such as www.speedtest.net.
I am just playing around and trying to make a very simple CMS. Right now I what I do right now is I use "FtpWebRequest" to get the file that they want to change around and stick it into a jquery plugin call html area(rich html editor).
Now I am wondering how could I allow them to add images that are not already hosted? Ie not on imageshack or something.
I am guessing I need to somehow upload the file and then store it somewhere but not sure how to do all that.
Thanks
A common approach for CMS systems that need to work in low-trust environments (like shared hosting) is to use the FileUpload control, and save the uploaded file as a binary (BLOB) in a database. This avoids dealing with the headache of disk access rights on the web server.
If you're using SQL Server, here's a great article on the database side of things (storing images as BLOBs).
The .NET side of things is pretty straightforward. The FileUpload.PostedFile property has all the information about the uploaded file, including a byte stream of its data.