Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I need to send the selected image to a web server. The code for selecting the image from the sdcard is shown below. I have searched many times in google. But still not finding a proper solution to my problem. Can anyone please suggest me how to send the selected image to a web server. The web server is a ASP.net web server. I have found many code to send data to php web server on the internet, but didn't find a code to send to an ASP.net web server. Please help me out. I'm new to android. So I didn't know the steps of sending image/ video data through a web server.

// I have added a button to select the image

Button imgbrowse=(Button)findViewById(R.id.imgbrowse); 

imgbrowse.setOnClickListener(new OnClickListener() 
{

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(i, RESULT_LOAD_IMAGE);

        }
});

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
        Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };

        Cursor cursor = getContentResolver().query(selectedImage,
                filePathColumn, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);

//the path where the image is located is stored in string variable

String picturePath = cursor.getString(columnIndex);         
        cursor.close();

    //Displaying the selected image in the image view. 

        ImageView imageView = (ImageView) findViewById(R.id.imageView1);
        imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

    //Displaying the path of the selected image

        TextView tv=(TextView)findViewById(R.id.textView5);
        tv.setText(picturePath);

    }
}
Posted
Updated 27-Jun-18 2:24am

1 solution

You can use HTTP client to send image to server
 
Share this answer
 
Comments
Richard Deeming 27-Jun-18 10:06am    
FOUR YEARS too late, and you couldn't even throw in a code sample?

Stick to answering recent questions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900