当我尝试将Base64编码的字符串上载到Flask应用程序时,获取'com.android.volley.NoConnectionError:java.net.SocketException:Broken pipe'

时间:2019-07-15 16:29:13

标签: android flask android-volley androidhttpclient

正如标题所清楚描述的那样,当我尝试将com.android.volley.NoConnectionError: java.net.SocketException: Broken pipe编码的Base64(实际上是String对象)上传到{时,会收到Bitmap错误{1}}应用使用Flask

以下是客户端代码:

Volley编码为Bitmap的辅助方法:

String

通过public String getStringFromBitmap(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] imageBytes = baos.toByteArray(); String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT); return encodedImage; } 发出POST请求:

Volley

对于后端,我使用StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() { @Override public void onResponse(String response) { Toast.makeText(CameraActivity.this, "onResponse is called", Toast.LENGTH_SHORT).show(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e(TAG, "onErrorResponse: ", error); } }) { @Override protected Map<String, String> getParams() { Map<String, String> params = new Hashtable<>(); params.put("image", getStringFromBitmap(image)); return params; } }; requestQueue.add(stringRequest);

Flask

p.s。为here定义内容长度的限制对我的情况不起作用。

0 个答案:

没有答案