Error using jQuery Upload File Plugin, unwanted strings appended to files (WebKitFormBoundary)
Asked Answered
S

1

1

I'm using this plug-in : 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.

Uploads works fine, but the problem is that images, exe, etc. Uploads broken. If I open uploaded files with a text editor, I can see unwanted strings

At begin:

------WebKitFormBoundaryPUTfurckDMbpBxiw Content-Disposition: form-data; name="file"; filename="image.png" Content-Type: image/png

At end:

------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?

Sheepfold answered 16/5, 2014 at 4:21 Comment(0)
S
1

Finally I found the answer here:

Reading file input from a multipart/form-data POST

I need to import a component from here 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)
    }
}
Sheepfold answered 16/5, 2014 at 18:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.