2014-05-16 114 views
1

我使用这个插件不需要的字符串:http://hayageek.com/docs/jquery-upload-file.php错误,附加到文件(WebKitFormBoundary)

,我用它来发送文件给一个WCF REST服务,并保存其硬盘上。

上传工作正常,但问题是,图像,EXE等上传破碎。 如果我打开上传的文件用文本编辑器,我可以看到不必要的字符串

在开始:

------ WebKitFormBoundaryPUTfurckDMbpBxiw内容处置:表格数据; NAME = “文件”;文件名= “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:\inetpub\wwwroot\UploadedComponents\" & 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 

任何想法解决这个问题?

回答

1

最后我找到了答案在这里:

Reading file input from a multipart/form-data POST

我需要从这里Multipart Parser导入一个组成部分。

然后保存在服务上这样上传的文件:

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) 
    } 
}