I looked through existing questions but could not find exact match. Maybe I’m missing something obvious, if so – please direct me in the proper place. Here is my problem:
I have ExtJs front and application that needs to upload binary data to the WCF back end. On the front end I have the following code (I use Ext.form.field.File control to let user select a file)
// Create a dummy form in the controller after user selected a file
var form = Ext.create('Ext.form.Panel', {
items: [ my_file_field ]
});
form.getForm().submit({
method: 'POST',
url: 'myservice.url',
...
});
On the backend I have the following contract:
namespace MyApp
{
[ServiceContract]
public interface ITransferService
{
[OperationContract]
[WebInvoke(UriTemplate = "UploadImage", Method = "POST")]
void SaveImage(Stream buffer);
}
}
It works ‘fine’ except one little thing: in the stream inside SaveImage() I get not only binary data from the file user selected but also bunch of headers and encoded fields:
------WebKitFormBoundary26wAkvwGTnAMELFM
Content-Disposition: form-data; name="ext-gen1654"; filename="photo.png"
Content-Type: application/octet-stream
..... binary data goes here ....
------WebKitFormBoundary26wAkvwGTnAMELFM--
What am I missing? How do I change the contract of the service so I get clean binary data?
I found this post: http://antscode.blogspot.com/2009/11/parsing-multipart-form-data-in-wcf.html
Does anybody know more simple solution? Not that proposed parsing logic is complicated, but I was under impression that this is a common task and there are should be easier way of doing it. I can’t believe MSFT doesn’t understand standard web pages POSTs in the WCF out-of-the-box…