Archived Forum Post

Index of archived forum posts


Chunk binary to browser with ckData example

Jul 09 '12 at 14:57


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


A better fit would be to use the Chilkat CkFileAccess ActiveX
(see )

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


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 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...


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