Returning large data in HandleSpecialURL Slow

Hi,
I’ve written a web service that returns documents to client web applications. The web service reads the document from a file location using a BinaryStream and then does a Request.Print in HandleSpecialURL to return the data to the browser. I return True to indicate that the data should be displayed.


'  A string to hold the data
Dim ReturnData As String

' Read in the 30MB of File Data
ReturnData = GetFileData()

' Print the Data to the WebRequest Object
Request.Print ReturnData

' Indicate to the browser that data should be displayed
Return True

This all works fine. However, if the file I’m returning is large e.g. 30MB (which isn’t massive really), then there is typically a 30sec delay between when HandleSpecialURL routine ends and before the browser starts to respond to the data.

Any suggestions?

Instead of loading the data into ram and then writing it, you should consider setting the File property of the WebRequest…

http://documentation.xojo.com/api/web/webrequest.html#webrequest-file

Doing so will write the data directly to the socket in chunks.

If the file is directly accessible by the web server, you might also try redirecting the browser to it…

Request.Header(“Location”) = “url pointing to the file” Request.status = 301 Return True

Thanks Greg!
I used the WebRequest.File property as suggested and that sorted it.

A couple of things to note for the others.

  1. You need to specify the MIME type of the file to return
  2. If you DON’T want the file to download and be displayed in the browser instead, then reset the following header value:
Request.Header("Content-Disposition") = ""