我想将图像从android上传到我的AWS EC2节点js服务器
但是在这篇文章中How to send an image from Android client to Node.js server via HttpUrlConnection?
我的Android应用程序已关闭
OutputStream os = conn.getOutputStream();
这段代码即使我设置了正确的网址。
问题是什么,任何人都有更好的想法将图像从android上传到节点?
答案 0 :(得分:0)
我认为你必须在AsyncTask中调用这个函数postData:
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);