Android客户端,将我们的通用的bitmap转为jpg字节数组:
static byte[] compress(final Bitmap bitmap) {
if(bitmap == null){
return null;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, QUALILY, out);
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
return out.toByteArray();
}
然后,我们通过Base64.encodeToString将这个数据加密成一个字符串,就可以当作json的一项作为jsonstring发送给服务端。
Python服务端,解密然后保存到jpg文件即可:
而下载文件更简单,使用PIL.Image,可以读出imagedata,然后写到BytesIO中即可。
服务端的读写代码如下: