0

I want to upload image from android to my AWS EC2 node js server

but in this post How to send an image from Android client to Node.js server via HttpUrlConnection?

my android application was shut down in

OutputStream os = conn.getOutputStream();

this code even though I set the correct url.

What is the problem, anyone have better idea uploading image from android to node?

Community
  • 1
  • 1
Kunbu
  • 3
  • 2

1 Answers1

0

I think you must call this function postData in AsyncTask like that :

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();
    }
}

and in your program main you can call this AsyncTask like that :

new UploadAsync().execute(bitmap);
Zakariaa Oulhafiane
  • 407
  • 1
  • 4
  • 11