上传更大尺寸的图像时获取com.android.volley.ServerError

时间:2017-11-17 12:22:08

标签: android android-volley

提前致谢。我使用Android排球库以Base64字符串格式将图像上传到服务器。对于尺寸小于500千字节的小图像是好的。 但对于尺寸超过500 kb的大尺寸图像。 我的代码是从图库中获取图像 -

Cursor cursor =   
                getApplicationContext().getContentResolver().query(imageUri, 
                filePath, null, null, null);
                cursor.moveToFirst();
                String imagePath = 
                cursor.getString(cursor.getColumnIndex(filePath[0]));
                cursor.close();
                BitmapFactory.Options options = new BitmapFactory.Options();

                Bitmap bitmap;
                options.inJustDecodeBounds = true;

                int heightRatio = (int)Math.ceil(options.outHeight/(float)300);
                int widthRatio = (int)Math.ceil(options.outWidth/(float)300);
                if (heightRatio > 1 || widthRatio > 1){
                    if ( heightRatio > widthRatio){
                        options.inSampleSize = heightRatio;
                    } else {
                        options.inSampleSize = widthRatio;
                    }
                }
                options.inJustDecodeBounds = false;


                bitmap = BitmapFactory.decodeFile(imagePath, options);

                int numBytesByCount = bitmap.getByteCount(); 

的 并将字符串作为map放入下面给出的函数中 的

public void volleyPostRequest(Activity activity,  String taleUrl, String message, GenerateResponse generateResponse, final Map<String, String> params){
        final ProgressDialog progress  = new ProgressDialog(activity);
        progress.setMessage("Loading");
        progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progress.setIndeterminate(false);
        progress.setCancelable(false);
        progress.show();
        if (isOnline()){
            CommonUtility.customShowToast(mContext, "Please check your network connection");
            progress.dismiss();
            return;
        }
        this.mGenerateResponse = generateResponse;
        RequestQueue requestQueue = Volley.newRequestQueue(mContext);
        String url = CommonUtility.BASE_URL+taleUrl;

        StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        progress.dismiss();
                        NetworkConnection.this.mGenerateResponse.success(response);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                CommonUtility.customShowToast( mContext, "Can't reach server" );
                NetworkConnection.this.mGenerateResponse.errorOnConnection(error.toString());
                progress.dismiss();
            }
        }){
            @Override
            public Map<String, String> getParams(){
                return  params;
            }

        };
        stringRequest.setRetryPolicy(new RetryPolicy() {
            @Override
            public int getCurrentTimeout() {
                return 100000;
            }

            @Override
            public int getCurrentRetryCount() {
                return 50000;
            }

            @Override
            public void retry(VolleyError error) throws VolleyError {

            }
        });

        requestQueue.add(stringRequest);

    }

0 个答案:

没有答案