简体   繁体   English

使用jQuery上传文件插件时出错,不需要的字符串附加到文件(WebKitFormBoundary)

[英]Error using jQuery Upload File Plugin, unwanted strings appended to files (WebKitFormBoundary)

I'm using this plug-in : http://hayageek.com/docs/jquery-upload-file.php 我正在使用此插件: http : //hayageek.com/docs/jquery-upload-file.php

I'm use it to send files to a WCF Rest Service and save its on hdd. 我用它来将文件发送到WCF Rest Service并将其保存在HDD上。

Uploads works fine, but the problem is that images, exe, etc. Uploads broken. 上传效果很好,但是问题是图像,exe等。上传损坏。 If I open uploaded files with a text editor, I can see unwanted strings 如果使用文本编辑器打开上传的文件,我会看到不需要的字符串

At begin: 开始时:

------WebKitFormBoundaryPUTfurckDMbpBxiw Content-Disposition: form-data; ------ WebKitFormBoundaryPUTfurckDMbpBxiw Content-Disposition:表单数据; name="file"; NAME = “文件”; filename="image.png" Content-Type: image/png filename =“ image.png”内容类型:image / png

At end: 最后:

------WebKitFormBoundaryPUTfurckDMbpBxiw-- ------ WebKitFormBoundaryPUTfurckDMbpBxiw--

My service code: 我的服务代码:

<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 

Any idea to solve that? 有解决的办法吗?

Finally I found the answer here: 最后,我在这里找到了答案:

Reading file input from a multipart/form-data POST 从多部分/表单数据POST读取文件输入

I need to import a component from here Multipart Parser . 我需要从这里Multipart Parser导入一个组件。

And then save the file uploaded at on service so: 然后保存在服务中上传的文件,以便:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM