在Android中通过node.js将图像从一个设备发送到另一个设备

我想从一个设备发送图像到另一个,所以我通过node.js创build了这个东西。 我已经将图像转换为base64,然后转换为string,然后将其发送到node.js服务器,并将该string解码到另一个设备,everythig完美。 我用过socket.io。 现在问题出现了,因为我收到了来自node.js的json响应的string,完整的响应没有得到响应的一半被修剪的地方。 所以基本上我没有得到完整的JSONRESPONSE。 这是我的node.js代码。

onLine[data.to].emit('newPrivateMessage1',{from:name, img:data.img.toString('base64'), type:'Private Msg1'}) 

这是我发送图像的第一个设备。

 JSONObject json1 = new JSONObject(); String filepath = Environment.getExternalStorageDirectory().toString()+"/1.png"; File file = new File(filepath); String itemname = getIntent().getStringExtra("itemname"); try { @SuppressWarnings("resource") FileInputStream imageInFile = new FileInputStream(file); byte imageData[] = new byte[(int) file.length()]; Log.e("TAG", "IMAGEFATABYTE:::" + imageData); imageInFile.read(imageData); String imageDataString = android.util.Base64.encodeToString(imageData, 0); json1.put("img", imageDataString); json1.put("to", itemname); Log.e("TAG", "MESSAGE:::" + json1); socket.emit("privateMessage1", json1); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } 

这是我的第二个获得json响应的设备

 String josn = getIntent().getStringExtra("pvtjson"); Log.e("TAG5", "IMAGEJSON" + josn); try { JSONObject jobj = new JSONObject(josn); jobj.get("img"); byte[] decodedString = Base64.decode(jobj.get("img").toString(), Base64.DEFAULT); Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); iv.setImageBitmap(decodedByte); } catch (JSONException e) { e.printStackTrace(); }