如何将图像请求(POST)发送到URL?

时间:2017-02-10 15:47:56

标签: android http cloudsight

sending to this (docs)

我正在尝试将图像从Android发送到他们的/image_requests端点,我正在尝试使用loopj。

所以我使用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();
        }
    }

然后我有了这个img位图,然后我尝试上传它:

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

                        );
                    }
                });

但我从服务器收到此错误:

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

显然我已经设置了图像位图,所以发生了什么?

0 个答案:

没有答案