Here's my WCF REST endpoint:
[WebInvoke(Method = "POST", UriTemplate = "_test/upload")]
public void UploadImage(Stream data)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.OK;
try
{
var parser = new MultipartParser(data);
var ext = Path.GetExtension(parser.Filename);
var filename = string.Format("{0}{1}", Guid.NewGuid().ToString("N"), ext);
var folder = HttpContext.Current.Server.MapPath(@"~\Uploads\");
var filepath = Path.Combine(folder, filename);
File.WriteAllBytes(filepath, parser.FileContents);
}
catch (Exception)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.InternalServerError;
}
}
And I'm using the multipart parser from here: http://antscode.blogspot.com/2009/11/parsing-multipart-form-data-in-wcf.html
My issue is that the above works great for some files (.bat, .txt, .cs, .doc) - I see in Fiddler all the good signs including the 200 (OK) status.
When I try to upload other files (.xls, .vsd), it fails with a 400 (Bad Request) status. I'm very surprised that a .doc would work and a .xls and .vsd would fail.
It is consistent as well. I've uploaded several .doc files successfully without any failures. I've also tried to upload several .xls files - some succeed, some fail (the successes are consistent over and over, the failures are consistent over and over). As I write this and test more and more files, there is a .pdf file that consistently produces a 504 (Fiddler - Receive Failure) error.
FYI, I am using Flex on the client and using the FileReference class to do the uploads. The Flex code is as standard as they come - using this code with the only change being the WCF REST URL: http://blog.flexexamples.com/2007/09/21/uploading-files-in-flex-using-the-filereference-class/
Any ideas why I am seeing some failures and some successes? I don't see the difference between the two?
Thanks in advance.