多个映像base64字符串未在没有压缩的情况下在服务器上发送

时间:2016-09-03 05:53:02

标签: android soap android-camera android-ksoap2

我想在我的应用中捕获五个图像,并将其base64字符串发送到服务器而不进行压缩。我在谷歌搜索并阅读了很多文章后,我发现解决方案发送base64字符串没有压缩。现在我想要的是当我只发送一张图像然后它的保存成功到我的服务器但是当我发送两个或两个以上的图像然后我得到以下错误我没有得到什么问题。我觉得我做错了。

public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == getActivity().RESULT_OK) {

            //user is returning from capturing an image using the camera
            if (requestCode == CAMERA_CAPTURE) {
                byte[] inputData=null;
                //Uri uri = data.getData();
                //get the Uri for the captured image
                Uri uri = picUri;
                Log.d("picUri", uri.toString());

                InputStream iStream = null;
                try {
                    iStream = getActivity().getContentResolver().openInputStream(uri);
                    inputData = getBytes(iStream);
                    encodedString = Base64.encodeToString(inputData, Base64.DEFAULT);

                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                //carry out the crop operation
                performCrop();

            } else if (requestCode == PIC_CROP) {
                //get the returned data
                Bundle extras = data.getExtras();
                //get the cropped bitmap
                thePic = (Bitmap) extras.get("data");

                if (setInImageView.equals("1")) {

                    imageView1.setImageBitmap(thePic);

                    image1 =encodedString;

                } else if (setInImageView.equals("2")) {

                    imageView2.setImageBitmap(thePic);

                    image2 = encodedString;

                } else if (setInImageView.equals("3")) {

                    imageView3.setImageBitmap(thePic);

                    image3 = encodedString;

                } else if (setInImageView.equals("4")) {

                    imageView4.setImageBitmap(thePic);

                    image4 = encodedString;

                } else if (setInImageView.equals("5")) {

                    imageView5.setImageBitmap(thePic);

                    image5 = encodedString;

                    String str;
                    str = "1";

                }

            }
        }
    }



public void selectImage1() {
        try {
            //use standard intent to capture an image
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            String imageFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/picture.jpg";
            File imageFile = new File(imageFilePath);
            picUri = Uri.fromFile(imageFile); // convert path to Uri
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, picUri);
            startActivityForResult(takePictureIntent, CAMERA_CAPTURE);
        } catch (ActivityNotFoundException anfe) {
            //display an error message
            String errorMessage = "oops! your device doesn't support capturing images!";
            Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_SHORT).show();
        }
    }

    //OnClick for set Image in Image View
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.camera1:
                // code
                setInImageView="1";
                selectImage1();
                break;
            case R.id.camera2:
                // code
                setInImageView="2";
                selectImage1();
                break;
            case R.id.camera3:
                // code
                setInImageView="3";
                selectImage1();
                break;
            case R.id.camera4:
                // code
                setInImageView="4";
                selectImage1();
                break;
            case R.id.camera5:
                // code
                setInImageView="5";
                selectImage1();
                break;

            default:
                break;
        }
    }


    public static byte[] getBytes(InputStream inputStream) throws IOException {
        ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
        int bufferSize = 10240;
        byte[] buffer = new byte[bufferSize];

        int len = 0;
        while ((len = inputStream.read(buffer)) != -1) {
            byteBuffer.write(buffer, 0, len);
        }
        return byteBuffer.toByteArray();
    }

}

以下是我的错误 -

SoapFault - faultcode: 'soap:Server' faultstring: 'There was an exception running the extensions specified in the config file. ---> Maximum request length exceeded.' faultactor: 'null' detail: org.kxml2.kdom.Node@97e9569

1 个答案:

答案 0 :(得分:0)

我解决了它并希望它能帮助别人。我在我的网络服务中添加了以下行。现在它保存了所有五个图像成功和非常好的质量和1.40 MB大小。

<configuration>
    <system.web>
        <httpRuntime maxRequestLength="1048576" />
    </system.web>
</configuration>