How to send image request (POST) to url?

657 Views Asked by At

sending to this (docs)

I am trying to send an image from Android to their /image_requests endpoint, and I am trying to use loopj.

So I take an image using the camera_intent:

 private void dispatchTakePictureIntent() {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            img = (Bitmap) extras.get("data");
            imageView.setImageBitmap(img);
            getData();
        }
    }

Then I have this img bitmap, and then I try to upload it:

SyncHttpClient client = new SyncHttpClient(
                );
                client.addHeader("Authorization", "CloudSight " + KEY);
                RequestParams files = new RequestParams();
                //params.put("Authorization", "CloudSight " + KEY);
                files.put("image_request[image]", img);
                files.put("image_request[locale]", "en-US");

                client.post(BASE_URL, files, new TextHttpResponseHandler() {
                    @Override
                    public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                        // error handling
                        // success
                        System.out.println(statusCode + "  " + responseString

                        );
                    }

                    @Override
                    public void onSuccess(int statusCode, Header[] headers, String responseString) {
                        // success
                        System.out.println(statusCode + "  " + responseString

                        );
                    }
                });

But I get this error from the server:

 {"error":{"image":["at least one of image or remote_image_url must be set"]}}

Clearly I have set the image bitmap, so what is happening?

0

There are 0 best solutions below