1
我正在使用WCF Web服务,并且我很好奇是否有任何方法可以将流转换为文件。 偶尔我会遇到“跨源请求错误”的问题,关于post方法,我意识到每当我接收到数据流时都没有问题。 但现在我要发布的图像我的方法以同样的方式(如果有一种方法)将流转换为文件
这是我的代码:
[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;
}
编辑:
HTML代码:
<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);
}
});
});
您正在使用哪个版本的.NET? –
我正在使用.NET 4 – ToTa