0

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?

CDub
  • 13,146
  • 4
  • 51
  • 68
fasasa
  • 13
  • 1
  • Your error just not have to do with android. You need to see the way your backend are expecting the image. – jonathanrz Feb 10 '17 at 16:45
  • @jonathanrz, I know the error now. I need to convert the bitmap to a file somehow – fasasa Feb 10 '17 at 16:46
  • Are you sure? Usually you need to pass an InputStream. Also, if you need a File, you just need to create a File object and save it, the problem is where to save it. Here you have more info: https://developer.android.com/training/basics/data-storage/files.html?hl=en – jonathanrz Feb 10 '17 at 16:49
  • @jonathanrz, I need to pass it a "file" as it says. – fasasa Feb 10 '17 at 16:49
  • Hi, did you solve the problem, if yes can you share? i have the same issue with cloudsight – Katherina Oct 04 '17 at 08:26

0 Answers0