2016-03-03 58 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);