0

I want to upload an image to server in the form of Byte array.. Here I am using surface view and 'Take Picture' button, when user click a take picture button, then

    TakePicture.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
        // TODO Auto-generated method stub
        camera.takePicture(null, null, callback);
    }
});

and pictureCallback is:

       PictureCallback callback = new PictureCallback(){

 public void onPictureTaken(**byte[] data**, Camera camera) {
  // TODO Auto-generated method stub

     try {
            //async task for storing the photo
         Log.i("Picture Taken.", "Picture Taken.");

            new SavePhotoTask(CameraPreviewActivity.this, data).execute();
        } catch (final Exception e) {
            //some exceptionhandling
            Log.i("Save Photo exception",e.getMessage());
        }

}}; Now here I am using this byte array 'data'

and I want to send this image in the form of byte[] to web server..

What should I do for this??

Kanika
  • 10,648
  • 18
  • 61
  • 81

2 Answers2

0

convert byte array to base64

String encodedImage = Base64.encodeToString(byteArrayImage, Base64.DEFAULT);

also see this link

MAC
  • 15,799
  • 8
  • 54
  • 95
0

1)Send camera intent

public void onCameraClick(View view) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    imageFile = FileUtil.newFile();
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
    startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}

2)get file path when the picture will be ready, read bytes from file and send bytes to a server.

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK){
            if (resultCode == RESULT_OK) {
                final String path = imageFile.getAbsolutePath();
// get file from path and send bytes to server
            }
        }
    }
Yahor10
  • 2,123
  • 1
  • 13
  • 13