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?

gsubiran
  • 2,012
  • 1
  • 22
  • 33

1 Answers1

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)
    }
}
Community
  • 1
  • 1
gsubiran
  • 2,012
  • 1
  • 22
  • 33