繁体   English   中英

将图片从图库上传到远程服务器(Titanium-android)

[英]Uploading Image from gallery to remote server (Titanium-android)

我正在使用Titan开发Android应用程序,在我的应用程序中,我需要将图像从图库上传到远程服务器位置。我已经尝试过了

button1.addEventListener('click',function(e)
{   
  Titanium.Media.openPhotoGallery({
  success : function(event) 
  {
     var update_pic = Titanium.Network.createHTTPClient();
     update_pic.onerror = function()
    {
     Titanium.API.info('error');
     alert(JSON.parse(this.responseText).error);
    }
    update_pic.onload = function() 
    {
     actInd.hide();
    }
   update_pic.open('POST','server-address/profile/update.json');
   update_pic.send(
        { 
          "user[avatar]":event.media,
          "authenticity_token":"sD5hjlI=",
          "user[name]":'nilesh', 
          "commit":"Update Profile" 
        });
   }
   })   

})

但是它对我不起作用。 进程在用户[avatar]:event.media点停止。这是将图像发送到远程服务器的正确方法。 我也尝试过

update_pic.send({
    user_avatar         : event.media,
    authenticity_token  : "sD5hjlI=",
    user_name           : 'nilesh',
    commit              : "Update Profile"
})

当我发送这样的参数时,它不会发送我的http请求,而当我删除user_avatar:event.media时,它发送我的请求意味着user_avatar存在问题。任何解决方案....需要帮助。 谢谢..........

尝试在“ var update_pic = ...”下面添加此行

update_.setRequestHeader(“ ContentType”,“ image / jpeg”);

摘自: http : //developer.appcelerator.com/question/9481/how-to-upload-images-with-filename-to-the-server

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM