login about faq


Can you make an example in Classic ASP for sending chucnks of data to the browser using CKData? This would be similar to the way File Access can chuck to the browser. Sending large pdf files via the chunk method works very well.


DocSize = FAC.FileSize(PDFName)
fac.FileOpen(PDFName, accessMode, shareMode, createDisp, fileAttr)

Response.ContentType = sContentType
Response.AddHeader "Content-transfer-encoding", "binary"
Response.AddHeader "content-length", DocSize
Response.Addheader "content-disposition", "inline;filename=" & FileName

' Stream the file to the output:
Dim dataChunk
Do While (fac.EndOfFile = 0)
  ' Read chunks of 4K at a time...
  dataChunk = fac.FileRead(4096)
  If (not (isNull(dataChunk))) then

End If

Set FAC = Nothing

asked Jul 05 '12 at 19:11

emartinson's gravatar image


A better fit would be to use the Chilkat CkFileAccess ActiveX
(see http://www.chilkatsoft.com/refdoc/xCkFileAccessRef.html )

The programming would be virtually identical to how you are using FAC in your example above.


answered Jul 06 '12 at 19:02

chilkat's gravatar image

chilkat ♦♦

I do not see how I can incorporate CKFileAccess. The class currently downloads the file from RackSpace CloudFiles as base64 data directly in to CKData (CKData.LoadBase64 CKHttpResponse.Body). I am trying to make my class flexible enough to either send the data to the users browser, flush to disk or pass in memory.

The sample code above is based on your FileAccess code sample. I am sure there is way with CKData to do the same. You have the method "GetChunk(fromIndex As Long, numBytes As Long) As Variant". I am not sure how to use "fromIndex" in a loop. The rest should be the same as above.

(Jul 06 '12 at 19:44) emartinson

HTTP requests and responses are MIME. The HttpResponse.Body property returns the response body (i.e. the content of the HTTP response MIME body) already decoded. In other words, you don't need to worry about the Content-Transfer-Encoding MIME header, which indicates how the content of the MIME body is encoded, such as "base64", "quoted-printable", "8bit", etc.

Therefore, this would be incorrect: dataObj.LoadBase64 responseObj.Body

You would instead do this: dataObj.LoadBinary responseObj.Body

The CkData ActiveX API provides a GetChunk method (see http://www.chilkatsoft.com/refdoc/xCkDataRef.html) such that you can get any chunk of the entire data by specifying a start index and length. There is also a NumBytes property that is the total number of bytes. Therefore, you can write a loop that gets chunk-by-chunk and sends it to the response...


answered Jul 09 '12 at 14:08

chilkat's gravatar image

chilkat ♦♦

It works now. If anyone is interested, here is the final code to send the binary data in chucks to the browser.

With Response
    .Expires = 0
    .ContentType = "application/pdf"
    .AddHeader "Content-transfer-encoding", "binary"
    .AddHeader "content-length", oData.NumBytes
    .AddHeader "Content-Disposition", "inline;filename=" & CI("FileName")

'   Send the body of the http request to the body of this response
    '   *Loop here to send chunks to the browser
    TheOffset = 0
    TheSize = 4096

Do Until TheOffset > oData.NumBytes
        .BinaryWrite oData.GetChunk(TheOffset, TheSize)
        TheOffset = TheOffset + TheSize


End With

answered Jul 09 '12 at 14:55

emartinson's gravatar image


Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Jul 05 '12 at 19:11

Seen: 2,926 times

Last updated: Jul 09 '12 at 14:57

powered by OSQA