views:

125

answers:

1

I've seen the Silverlight upload sample here referenced multiple times on this site and elsewhere, but I have a question about whether or not it's really safe.

Quick review: This code does "chunked" uploading to an ASHX handler. UploadFileChunk() instantiates a WebClient and uses OpenWriteAsync and an OpenWriteCompletedEventHandler to send some bits from a file. The WebClient communicates with the handler using a URI with two QueryString parameters: "filename" and "append." After writing the bits in a chunk to the WebClient's output stream, the event handler checks to see if all the bits have been sent, and if not it calls UploadFileChunk() again to send another chunk.

On the server side, the handler is simple - write the bits to disk using a FileStream, appending if append=1 and creating anew if append=0.

This architecture seems very likely to result in problems. Is the server guaranteed to be finished writing the bits and closing the filestream before it receives the next request and starts appending bits from the next chunk? My understanding of the OpenWriteCompletedEventHandler on the Silverlight side is that when you finish the write operation and close the stream, that doesn't necessarily mean the bits have been sent across the wire yet, let alone been processed by the server-side handler.

Thanks!

+1  A: 

If you have any concerns about uploading larger files (I have seen reports of problems with very large files), try one of the free Silverlight Open Source file uploaders like this one

Enough already