PhoneGap文件上传到WCF

时间:2012-06-06 18:44:12

标签: wcf file-upload cordova

如何将图像从移动设备上传到我的外部数据库?

这是我目前的WCF服务:

界面:

[WebInvoke(UriTemplate = "/Upload", Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped), CorsEnabled]
string UploadProfileImage(string image);

班级方法:

public string UploadProfileImage(string image)    
{ 
    // Upload code needs to go here. 
}

我可以使用ajax发布就好了,我只是迷失了如何使用图像。

以下是我如何发帖的jQuery示例。

// This is the success function that gets called after selecting an image from my device
function uploadSuccess(imageURI) {
    uploadImage(imageURI);
}

function uploadImage(imageURI)
{
    var data = '{"image":"' + imageURI + '"}'
    $.ajax({
        url: "http://192.168.101.55:8848/api/Upload",
        type: "POST",
        contentType: "application/json",
        data: data,
        success: function (result) {

        },
        error: function (jqXHR, textStatus, errorThrown) {

        }
    });
}

1 个答案:

答案 0 :(得分:0)

我认为由于跨域发布限制,你无法使用jquery实现这一点。
你必须创建表单并将表单“action”指向服务方法的url,添加enctype =“multipart / form-数据“到表格标签。
不要忘记将服务输入参数类型更改为“stream”

相关问题