The system is a Flex application that interacts with the WCF REST web service. I am trying to upload a file from a Flex application to a server, and I am encountering some problems, I hope someone here can help. I am using FileReference in a Flex application to view and download a file as defined here:
http://blog.flexexamples.com/2007/09/21/uploading-files-in-flex-using-the-filereference-class/
Then I get the file as Stream (displayed as System.ServiceModel.Dispatcher.StreamFormatter.MessageBodyStream in the debugger) in the WCF REST web service (using the WCF 4 REST service project type)
[WebInvoke(Method = "POST", UriTemplate = "_test/upload")] public void UploadImage(Stream data) {
Note. CopyStream method used in this post: How to save a stream to a file in C #?
The file is saved without any problems. The problem is that the file contains more information than we would like. Here is the contents of the saved file (where the source file contains only "THIS FILE CONTENT"):
------------ae0ae0Ef1ae0Ef1ae0gL6gL6Ij5cH2 Content-Disposition: form-data; name="Filename" testfile.txt ------------ae0ae0Ef1ae0Ef1ae0gL6gL6Ij5cH2 Content-Disposition: form-data; name="Filedata"; filename="testfile.txt" Content-Type: application/octet-stream THIS IS THE CONTENT OF THE FILE ------------ae0ae0Ef1ae0Ef1ae0gL6gL6Ij5cH2 Content-Disposition: form-data; name="Upload" Submit Query ------------ae0ae0Ef1ae0Ef1ae0gL6gL6Ij5cH2--
The content looks as described in the Adobe documentation: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html
Is there any means in C # to get the contents of a file from Stream?
EDIT (3/24 8:15 pm) : what the Flex application sends is a multi-page POST form. How can I decode multiple body data represented by the Stream parameter and cut out pieces of the multi-body?
EDIT (3/25 10:00) : A few more stack overflow messages that are related:
WCF service to receive encrypted messages / form data POSTing multipart / form-data to WCF REST service: action changes
EDIT (3/25 10:45 AM) : Found a multi-parser parser that works very well:
http://antscode.blogspot.com/2009/11/parsing-multipart-form-data-in-wcf.html
Thanks in advance.
c # flex rest stream wcf
Ed sinek
source share