2016-03-03 57 views
0

我要上傳從Android的圖像到我的AWS EC2節點JS服務器Android的圖片上傳到節點JS

,但在這篇文章中How to send an image from Android client to Node.js server via HttpUrlConnection?

我的Android應用程序是

的OutputStream OS =關閉conn.getOutputStream();

這段代碼儘管我設置了正確的url。

什麼問題,任何人有更好的主意上傳圖像從Android到節點?

+0

你們是不是要執行這個操作在UI線程上,Android 3.0+設備不允許。 – CodingDefined

回答

0

我想你必須調用這個函數POSTDATA中的AsyncTask這樣的:

public class UploadAsync extends AsyncTask<Bitmap,Void,Void>{ 
    @Override 
    protected Void doInBackground(Bitmap... params) { 
     //Here you must call the function for sending the bitmap 
     postData(params[0]); 
     return null; 
    } 

    @Override 
    protected void onPostExecute(Void aVoid) { 
     super.onPostExecute(aVoid); 
     //Here you can put something to do when the task finished. 
     Toast.makeText(getBaseContext(),"Image Uploaded!",Toast.LENGTH_LONG).show(); 
    } 
} 

,並在程序主,你可以調用這個的AsyncTask這樣的:

new UploadAsync().execute(bitmap);