I'm using WCF web service and I'm curious if there is any way that I can convert Stream to file. Occasionally I'm having "cross origin request error" problems, on post methods, and I realized that whenever I receive data as Stream there are no problems. But now I want to post image to my method on the same way (if there is a way)
This is my code:
[OperationContract]
[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "SaveImage")]
public bool SaveImage(Stream streamData){
// read the streamData
// convert streamData to File
// with something like this: new FileStream(..streamData);
return true;
}
Edit:
Html Code:
<form><input type="file" name="file"/><div id="send">send</div></form>
Jquery ajax:
$('#send').click(function () {
var allDataFromTheForm = new FormData($('form')[0]);
$.ajax({
url: "/url/SaveImage",
type: "POST",
data: allDataFromTheForm,
cache: false,
contentType: false,
processData: false,
success: function (result) {
alert(result);
}
});
});