Http 将包含数据的图像上载到服务器

Http 将包含数据的图像上载到服务器,http,titanium,Http,Titanium,我有一些数据,我需要上传到服务器与图像使用 multipart/form-data 但我收到请求超时这是我的数据 var data={ property_name:p_n_txt.value, friendly_name:f_txt.value, property_type:clicked, size:space_Slider.getValue(), price:price_Slider.getValue(),

我有一些数据,我需要上传到服务器与图像使用

multipart/form-data    
但我收到请求超时这是我的数据

  var data={
       property_name:p_n_txt.value,
       friendly_name:f_txt.value,
       property_type:clicked,
       size:space_Slider.getValue(),
       price:price_Slider.getValue(),
       number_of_bedrooms:bedrooms_Slider.getValue(),
       number_of_bathrooms:bathrooms_Slider.getValue(),
       number_of_parkings:p_space_Slider.getValue(),
       location:a_txt.value,
       features:13,
       payment_method:4,
       image1_name:"image0.png",
       image1:Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory,Ti.App.Properties.getString("filename")),

   };    
而httpclient是

var xhr = Ti.Network.createHTTPClient({
    onload: function() {
    var myData = JSON.parse(this.responseText);
    console.log(this.responseText);


    },
    // function called when an error occurs, including a timeout
    onerror : function(e) {
    Ti.API.debug(e.error);
    console.log(this.status);
    console.log(e.error);

    },
    timeout : 20000
    });

    xhr.open('POST','http://url/');
    xhr.setRequestHeader("enctype", "multipart/form-data");
     xhr.setRequestHeader("Content-Type", "image/png");
     // xhr.setRequestHeader("Content-Type", "image/jpeg");

    xhr.send(data);


});   
这里是表单数据,而不是json,因此无需添加
json.stringify

但我有4个案子我试过了

首先:使用stringify,如果我添加了contentType“image/png”,我得到了HTTP 415
和HTTP 500,如果我没有添加
第二次没有stringify,当我添加contentType“image/png”时,我得到了请求超时
当我没有添加它时,我得到了HTTP 413
关于如何完成这项事业,我发现了很多问题,但没有人对我有所帮助

谢谢

为什么不尝试将图像编码为Base64编码并将其传递给服务器端,只需对其进行解码,就可以继续了

Ti.Utils.base64encode(image.toBlob()).toString();
这可以发送到服务器,不需要发送任何头