1

I am developing android application using titanium and in my application I need to upload image from gallery to remote server location.I already tried this

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" 
        });
   }
   })   

})

But its not working for me. Process stop at point user[avatar]:event.media,.Is this the proper way to send image to remote server. I also tried this

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

when I send parameter like this, it not sending my http request and When I remove user_avatar : event.media It sending my request mean there is problem with user_avatar.Any solution....Need help. Thank you..........

nilkash
  • 7,408
  • 32
  • 99
  • 176

1 Answers1

0

try adding this line below "var update_pic = ..."

update_.setRequestHeader("ContentType", "image/jpeg");

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

Apotropaic
  • 11
  • 1
  • 1