Quantcast
Channel: Xojo Programming Forum - Latest topics
Viewing all articles
Browse latest Browse all 3695

WebResponse.File revelations

$
0
0

I have been struggling with getting responce.File in HandleURL to work the way I want it to.
By default it sets the Content-Disposition: html header to attachment; filename=“filename”

That header tells the browser to open a save dialog to save the file to disc, but I want to show the file (image) inline in the browser window instead.

Now, the documentation says that “Setting a header to a blank string removes the header.”
When trying to do that by setting response.Header("Content-Disposition") = "" I realized that for some reason this does not work, the header is not removed.

This made me fall back to using responce.Write(BinaryStream) in HandleURL to deliver the file instead, which also works.
Many others on here seems to be doing the same.

I finally got some time to create a bug for it, and make a little demo project showing the issue 78854

With the demo project in place it was easy for me to also do a little benchmarking and comparison between delivering an image with responce.File and responce.Write(BinaryStream) through HandleURL

Wooha, it seems that responce.File is up to 22x faster than responce.Write(BinaryStream) running locally in debug mode on my Mac.

That is a big performance gain for my webapps so I decided to see if there was some other way to get rid of the annoying “Content-Disposition” header that was preventing me from using responce.File to deliver my images with HandleURL.

Turns out it is very very easy.
All I had to do was set response.Header("Content-Disposition") = "inline" after setting the responce.File

At the end this gave me over 100% real life performance increase on my live webapps so Im happy, but I wish it would have been in the docs somewhere.

Just wanted to share this if there are others out there using responce.Write(BinaryStream) in HandleURL because you can not get responce.File to work for inline content.

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 3695

Trending Articles