Guillermo Subiran Guillermo Subiran - 3 months ago 143x
jQuery Question

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

I'm using this plug-in :

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:


My service code:

<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
Dim absFileName As String = "C:\inetpub\wwwroot\UploadedComponents\" & fileName
Using fs As New FileStream(absFileName, FileMode.Create)
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

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)