Windows 8将图像发布到Web服务器

时间:2013-01-16 18:16:18

标签: javascript windows windows-8

我有以下JavaScript代码来从人员应用中获取联系人姓名和缩略图。

 var picker = new Windows.ApplicationModel.Contacts.ContactPicker();
 picker.commitButtonText = "Select";
 picker.pickSingleContactAsync().done(function (contact) {
 if (contact !== null) {
     var name = contact.name
     contact.getThumbnailAsync().done(function (thumbnail) {
         if (thumbnail.size > 0) {
             var imageBlob = window.URL.createObjectURL(thumbnail);
             document.getElementById("img").src = imageBlob; 
             WinJS.xhr({ url: "http://host?name=" + name }).done(
                 function completed(rss) {

                 },
                 function error(request) {
                    // handle error conditions.
                 },
                 function progress(request) {
                    // report on progress of download.
                 }
             ); 
         }
     });
 }

我知道要将名称发送到网络服务器,但如何发送缩略图?

有人可以提供示例代码。

谢谢。

1 个答案:

答案 0 :(得分:1)

您可以使用WinJS.xhr()进行HTTP POST。这是一个例子:

How to upload binary data with WinJS.xhr

您只需设置以下选项:type: "POST", url: <URI of the website>, data: blob。首先创建blob,如示例所示。