Max
Max

Reputation: 1299

How to upload a file to WCF using jQuery by passing filePath as param and not using HTML File tag?

I've seen pretty good sample code using HTML5 but we have to develop a solution that works for most browsers. I found solutions that use iFrame and a nice AJAX plug in such as (https://github.com/blueimp/jQuery-File-Upload) but all samples are for PHP or use the HTML File tag ().

I need to create a WCF service that accepts a Stream and a simple jQuery AJAX call where I will pass the file path such as C:\TEST\FILE001.ZIP (instead of displaying the File TextBox with the BROWSE... button for the user to pick out the file).

Something like:

$.ajax(
{
async: false,
cache: false,
data: 
{
    "fileID" : "1234",
    "fileName" : "C:\TEST\FILE001.ZIP"
},
complete: function (jqXHR, textStatus)
{
},
error: function (jqXHR, textStatus, errorThrown)
{  
    alert("errorThrown: " + JSON.stringify(jqXHR) + '  ' + textStatus + '  ' + errorThrown )     
},
success: function (data, textStatus, jqXHR)
{       
},
type: "POST",
url: "svc/Test.svc/UploadFile"
});

How do I do that? The closest forum thread I found was this: Working example of AJAX file upload to WCF service but that didn't seem to be a complete answer as it did not work for me.

I also found this one which seems to be exactly what I need but no answer either: Upload a complex object to a WCF REST Service from JQuery

Thank you

Upvotes: 0

Views: 1522

Answers (1)

Piotr Stapp
Piotr Stapp

Reputation: 19830

You cannot just pass file location. It is because server side does not have access to client computer

The example you are looking for is here: https://github.com/maxpavlov/jQuery-File-Upload.MVC3

Upvotes: 1

Related Questions