[英]Uploading Image from gallery to remote server (Titanium-android)
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 我正在使用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"
});
}
})
})
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.
进程在用户[avatar]:event.media点停止。这是将图像发送到远程服务器的正确方法。 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. 当我发送这样的参数时,它不会发送我的http请求,而当我删除user_avatar:event.media时,它发送我的请求意味着user_avatar存在问题。任何解决方案....需要帮助。 Thank you..........
谢谢..........
try adding this line below "var update_pic = ..." 尝试在“ var update_pic = ...”下面添加此行
update_.setRequestHeader("ContentType", "image/jpeg"); update_.setRequestHeader(“ ContentType”,“ image / jpeg”);
taken from: http://developer.appcelerator.com/question/9481/how-to-upload-images-with-filename-to-the-server 摘自: http : //developer.appcelerator.com/question/9481/how-to-upload-images-with-filename-to-the-server
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.