Question

Byte serving

Asked by: rbhatia

Our web site has several PDF files that are uploaded directly to the web server for serving up via an ASP page. Since these PDF's are restricted to members only, we are controlling access and thus serving the PDF content via ASP pages (using the binarywrite) so that people cannot get to the PDF file directly.
Some of our PDF files are significantly large in size and sometimes they take forever to download. We have received several complaints from customers about how slow these PDF's are.
I came across Byte serving and was going to suggest my staff to check that they are enabling Web Fast View on these PDF's before they upload it to the server.
I also noted though that the web server must support byte serving. I am running IIS 5.0. Does that support byte serving out of the box or do I need to do something on the web server ?
Also, the way I'm serving these pages is by streaming them via ASP. Woudl that still support byte streaming ?
Please advise.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-03-24 at 07:20:39ID21363372
Tags

iis

,

byte

,

pdf

Topic

Adobe Acrobat

Participating Experts
2
Points
250
Comments
9

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. binarywrite with PDF problem
    I am trying to binarywrite a PDF file to the browser. No matter what I try, I just get the binary data in the browser, instead of acrobat opening. Please look at this code and tell me if you can find any problems. Thanks.. ---- ASP Set objBinFile = Server.CreateObjec...
  2. Binarywrite ASP
    Hey guys, I am connecting to SQL Server 2000 database and bring down data from BLOB fields by binarywriting the information from a html image src attribute. We basically have two files. File one.asp <img src="common/showpic.asp?id=2536252" border=0 width=90 ...
  3. BinaryWrite and SSL
    I'm creating a PDF file on the fly and feeding it to the browser using BinaryWrite. The website is secure (runnng SSL) and when the page displays it pops up the message: "This page both secure and non-secure items. Do you want to display the non-secure items?" Ho...
  4. How to get Dataset data into Byte array to Binarywrite to br…
    I am trying to send the contents of a dataset to a browser as a file using binarywrite but I've got to get the data out of the dataset and into a byte array first. I am trying to do this in the aspx.vb, if that matters. Can someone please show me how to do this? Thanks!
  5. Byte serving from ASP
    I'm trying to implement byte serving from ASP. Byte serving is that technique that allows an http client to receive file chunks instead than a whole, such as acrobat reader when it display the first pages way before the entire file has been downloaded. This is what I have im...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: khkremerPosted on 2005-03-24 at 10:07:33ID: 13624294

Any recent version of IIS does support byte-serving (which means that IIS 5.0 is OK). I do however not know if this is compatible with "binarywrite". I actually doubt it, because byte serving requires that the web server can access any part of the file. It's pretty easy to find out if byte-serving is supported: Open a large PDF file via the web server, and verify that the first page displays before the full file is downloaded, then do a "goto to page" and jump to e.g. the last page in the document. Does this page show up with only a small delay? Is this working for normally served files? If that's the case, does it also work with your files served via binarywrite?

If you find out that binarywrite() served files do not support byte serving, you need to think about a different way to serve them, but still making sure that direct connections do not work.

 

by: rbhatiaPosted on 2005-03-25 at 15:02:47ID: 13634013

Still was hoping someone could give me a sure-shot answer if byte streaming is supported when a PDF file is served using binarywrite().
I tried the above test but both files seem to open up equally fast however I'm still not convinced.
If I don't get an answer, I'll gladly give khkremer the points for his effort and good suggestions too.

 

by: khkremerPosted on 2005-03-25 at 15:09:10ID: 13634047

You have to try this with a large file (e.g. the Acrobat and PDF Library API Reference - http://partners.adobe.com/public/developer/acrobat/sdk/index_doc.html#plugins - this is a 15MB file and should give you enough time to jump around in the document while it's loading).

 

by: cipPosted on 2005-04-01 at 01:59:14ID: 13679439

ASP binarywrite does not support byte serving, it will stream all the pdf content in one time. To support byte serving via ASP, you should implement a script which interprets byte ranges requests.

For example if you get a request like this one:

GET [pdf file url] HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*
Referer: http://www.uninettuno.it/mednetu/e/papartners/downloadtest.asp
Accept-Language: it
Accept-Encoding: gzip, deflate
Range: bytes=24304-42765
If-Range: "0733742da35c51:992"
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Host: [host url]
Connection: Keep-Alive
Cookie: ASPSESSIONIDACRQCQSA=KEHLLHEDDOHFHGGMFFPBOMPM

You should serve the range 24304-42765, and your .asp script should be ready to called again to serve more ranges.

You might take a look at:

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21368039.html

The provided code still has a problem, it works well with acrobat read 7.0, but if the client uses a previous version, a "download file" dialog would appear. It's useful to show the point anyway.

 

by: cipPosted on 2005-04-01 at 06:05:25ID: 13680899

There you go, I fixed a couple of bugs. Now this is working with version 5,6 and 7 of acrobat reader.

var adTypeBinary = 1

function set_range(range, filesize){
  /*
  Sets the first and last bytes of a range, given a range expressed as a string
  and the size of the file.

  If the end of the range is not specified, or the end of the range is greater
  than the length of the file, $last is set as the end of the file.

  If the begining of the range is not specified, the meaning of the value after
  the dash is "get the last n bytes of the file".

  If $first is greater than $last, the range is not satisfiable, and we should
  return a response with a status of 416 (Requested range not satisfiable).

  Examples:
  $range='0-499', $filesize=1000 => $first=0, $last=499 .
  $range='500-', $filesize=1000 => $first=500, $last=999 .
  $range='500-1200', $filesize=1000 => $first=500, $last=999 .
  $range='-200', $filesize=1000 => $first=800, $last=999 .

  */
 
  var dash  = range.indexOf('-');
  var first = Trim(range.substr(0, dash))
  var last  = Trim(range.substr(dash+1));
  if (first=='') {
    //suffix byte range: gets last n bytes
    var suffix = last;
    last       = filesize-1;
    first      = filesize-parseInt(suffix);
    if(first<0) first = 0;
  }
  else
  {
    if (last=='' || parseInt(last) > filesize-1)
          last = filesize-1;
  }
 
  first = parseInt(first);
  last  = parseInt(last);
 
  if (first > last){
        /**
         ** Unsatisfiable range, sending status 416 will not work
         ** most of the times, but sending 0 content will.
         **/
        last = first+1;      
    //unsatisfiable range
    //Response.Status = "416 Requested range not satisfiable";
    //Response.CacheControl = "No-store"
    //Response.addHeader("Content-Range", "*/" + filesize);
    //Response.Flush();
    //Response.end
  }
 
  var returnobj = new Object();
  returnobj.first = first;
  returnobj.last  = last;       
 
  return returnobj;
}

function buffered_read(ostream, bytes, buffer_size)
{
      if (!buffer_size)
            buffer_size = 1024;
            
  /*
  Outputs up to $bytes from the file $file to standard output, $buffer_size bytes at a time.
  */
  var bytes_left = bytes;
  while(bytes_left > 0 && !ostream.EOS)
  {
    if(bytes_left > buffer_size)
      bytes_to_read = buffer_size;
    else
      bytes_to_read = bytes_left;
   
    bytes_left -= bytes_to_read;
   
    Response.BinaryWrite(ostream.Read(bytes_to_read));
    Response.Flush();
  }
}

function byteserve(filepath, filesize, contentdisposition, filename){
  /*
  Byteserves the file $filename.  

  When there is a request for a single range, the content is transmitted
  with a Content-Range header, and a Content-Length header showing the number
  of bytes actually transferred.

  When there is a request for multiple ranges, these are transmitted as a
  multipart message. The multipart media type used for this purpose is
  "multipart/byteranges".
  */
 
      Response.Clear
      var ostream = Server.CreateObject("ADODB.Stream")
      ostream.Open       
      ostream.Type = adTypeBinary
      ostream.LoadFromFile(filepath)      
      
      var boundary = "";
      var ipos = (""+Request.ServerVariables('HTTP_RANGE')).indexOf('bytes=')            
      
  ranges = new Array();
  if (Request.ServerVariables('REQUEST_METHOD')=='GET' && !isEmpty(Request.ServerVariables('HTTP_RANGE')) && (ipos >= 0))
  {
        range    = (""+Request.ServerVariables('HTTP_RANGE')).substr(ipos+6);
    boundary = '[lka9uw3et5vxybtp87ghq23dpu7djv84nhls9p]';//set a random boundary
    ranges   = range.split(",")
  }
 
  if (ranges.length > 0)
  {
    if (ranges.length > 1)
    {
          
          if (local_debug) dbl.write("Range > 1...");
      /*
      More than one range is requested.
      */

      //compute content length
      content_length = 0;
      for (var i=0; i < ranges.length; i++)
      {
        rangeobj = set_range(ranges[i], filesize);
       
        content_length += ("\r\n--" + boundary + "\r\n").length;
        content_length += ("Content-type: application/pdf\r\n").length;
        content_length += ("Content-range: bytes " + rangeobj.first + "-" + rangeobj.last + "/" + filesize + "\r\n\r\n").length;
        content_length += rangeobj.last - rangeobj.first + 1;          
      }
                  content_length += ("\r\n--" + boundary + "--\r\n").length;
                  
                  Response.status = "206 Partial content";
                   Response.CacheControl = "No-store"
          Response.addHeader("Accept-Ranges", "bytes");             
                  
      //output headers
      Response.addHeader("Content-Length", ""+content_length);
      Response.ContentType = "multipart/byteranges; boundary=" + boundary
     
      //output the content
      for (var i=0; i < ranges.length; i++)
      {
        rangeobj = set_range(ranges[i], filesize);
       
        Response.write("\r\n--" + boundary + "\r\n");
        Response.write("Content-type: application/pdf\r\n");
        Response.write("Content-range: bytes " + rangeobj.first + "-" + rangeobj.last + "/" + filesize + "\r\n\r\n");
        Response.Flush();
        ostream.position = rangeobj.first;
        buffered_read(ostream, rangeobj.last - rangeobj.first + 1);
      }
      Response.write("\r\n--" + boundary + "--\r\n");
      Response.Flush();
    } else {
      /*
      A single range is requested.
      */
                  Response.status = "206 Partial content";
                   Response.CacheControl = "No-store"
          Response.addHeader("Accept-Ranges", "bytes");                  
     
      range = ranges[0];
      rangeobj = set_range(range, filesize);  
      Response.addHeader("Content-Length", ""+(rangeobj.last - rangeobj.first + 1));
      Response.addHeader("Content-Range", "bytes " + rangeobj.first + "-" + rangeobj.last + "/" + filesize);
      Response.ContentType = "application/pdf";
      ostream.position = rangeobj.first;
      buffered_read(ostream, rangeobj.last - rangeobj.first + 1);
    }
  }
  else
  {
    //no byteserving
    Response.addHeader("Content-Length", filesize);
    Response.ContentType = "application/pdf";

            Response.addHeader("Content-Disposition", contentdisposition + "; filename=" + filename)        
    if (contentdisposition == "inline")
          Response.addHeader("Accept-Ranges", "bytes");
   
            buffered_read(ostream, filesize);
  }
  ostream.Close();
  ostream = null;
}

 

by: cipPosted on 2005-04-01 at 06:07:38ID: 13680914

The language is jscript of course, you'll have to include:

<%@ Language="JScript" %>

At the beginning of your ASP file.

 

by: rbhatiaPosted on 2005-04-19 at 14:17:02ID: 13819627

I am certain at this point that using binary write my PDF's are not supporting byte serving. I recently had an issue with a PDF that was showing up blank when served via my ASP page but the same file would display fine by directly pulling it as a PDF.
So I think I'm going to need some way to support byte serving via binary write.
I would like to award the points to CIP but I am currently testing the code to see if it works for me.
Thanks

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...