我使用这个插件:http://hayageek.com/docs/jquery-upload-file.php
我用它来发送文件到WCF Rest服务,并保存在硬盘上。
上传工作正常,但问题是图像,exe等。上传了。如果我用文本编辑器打开上传的文件,可以看到不需要的字符串
在开始:在结束------WebKitFormBoundaryPUTfurckDMbpBxiw Content-Disposition: form-data;name = "文件";filename="image.png"内容类型:image/png
:
——WebKitFormBoundaryPUTfurckDMbpBxiw
我的服务代码:
<OperationContract()>
<WebInvoke(ResponseFormat:=WebMessageFormat.Json, Method:="POST", UriTemplate:="GetFile?fileName={fileName}&accion={accion}")>
Function GetFile(str As Stream, fileName As String, accion As String) As String
Try
Dim absFileName As String = "C:inetpubwwwrootUploadedComponents" & fileName
Using fs As New FileStream(absFileName, FileMode.Create)
str.CopyTo(fs)
str.Close()
End Using
Return "Upload OK"
Catch ex As Exception
Throw ex
End Try
End Function
有解决这个问题的办法吗?
我终于在这里找到了答案:
从multipart/form-data POST读取文件输入
我需要从这里导入一个组件Multipart Parser
然后将上传的文件保存在on服务上,所以:
public void Upload(Stream stream)
{
string filepath = "some path with filename and extension"; // corrected filepath mistyping
MultipartParser parser = new MultipartParser(stream);
if (parser.Success)
{
// Save the file
File.WriteAllBytes(filepath, parser.FileContents)
}
}