簡體   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