How can I convert my Stream (image data) back into a file

Posted by James Hay on Stack Overflow See other posts from Stack Overflow or by James Hay
Published on 2010-05-06T12:17:38Z Indexed on 2010/05/06 12:28 UTC
Read the original article Hit count: 107

Filed under:
|
|

I have a WCF restful service that I'm trying to upload an image to. I have a very basic metod that accepts a stream as it's only parameter and is defined in the contract as:

[OperationContract]
[WebInvoke(UriTemplate = "ReviewImage", BodyStyle = WebMessageBodyStyle.Bare, Method = "POST")]
ReviewImage UploadImage(Stream data);

I'm actually consuming this service from flash (which is fairly inconsequntial) which selects a file from the file system and uploads it through the service url.

It all works seems to work, adding a breakpoint to the UploadImage method breaks as expected.

If I wanted to save this file back to disk, is it just a case of reading this Stream object into a FileStream object that creates the file somewhere? A bit like the this? When i do actually do this the file can not be opened as an image. I'm sure i'm missing a key piece of knowledge here. Does my stream actually contain just the image bytes or does it contain more than that?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about wcf