This project is read-only.

OnSendRawData and Images

Jul 23, 2008 at 9:20 AM

I am trying to intercept an image for additional processing but with the SendRawData handler I seem to get large images returned in several individual events.

Is there an alternative method or a suggestion as to how to manage images, both on the e.Context.GetData() and SetData().  I am confused (easily) as the byte array from GetData returns the same size for the multiple requests.

 Thanks - C

Jul 24, 2008 at 1:03 PM
... some time later ...

The images are processed in packets (in my case 4096 byte chunks).  So a single image comes streamed in many events.

If I catch the first two events and re-write the data with a e.Context.SetData( myBytes) then all is OK.  However, if I rewrite more than two the browser is not getting a diaplayable image.
I have also written the bytes to disk so I can see that the format is OK.

An example of handling a series of OnSendRawData events, getting the image and manipulating it (which of course means that the image size is out-of-step with the rest of the stream) would be great.

I have tried waiting until the end of the stream and doing a WriteClient() but in the meantime the original bytes have already been sent.  I tried cancelling the bytes but e.Context.SetData(null) did not seem to get me very far!

 Thanks in advance, Cris

Jul 28, 2008 at 6:57 PM
Hi Cris,

Subscribing to SF_NOTIFY_SEND_RAW_DATA, caching data, modifying it and send it to the client in an ISAPI Filter has always been been a performance killer in IIS/5.x and IIS 6. IIS 7 allows you to use kernel (http.sys) caching, but then again you always suffer from the memory problem due to caching the whole thing. As for the Filter.NET issue, you may try to set the byte array to 0 - new byte[0] - to avoid the original data from being sent. You then cache it until it ends - OnLog, or OnEndOfRequest - and then flush it to the client upon modification.

David Wang has some good pointers on ISAPI Filters issues and how-to's:

However ... you may find more useful and performant to deal with the images at another level, like an HttpModule. ISAPI Filters are quite delicate and affect the whole IIS, so care must be taken when taking this direction.

Hope it helps
Tiago Halm