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?

1
  • Are you trying to perform this operation on UI thread, which android 3.0+ devices won't allow. Commented Mar 3, 2016 at 5:29

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.