在httppost图片的传输中,将图片转为base64编码传送

path=数据库存放图片的路径

public static String imageToBase64(String path) {
    InputStream in = null;
    byte[] data = null;
    try {
        in = new FileInputStream(path);
        data = new byte[in.available()];
        in.read(data);
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    BASE64Encoder encoder = new BASE64Encoder();
    return encoder.encode(data);
}

你可能感兴趣的:(学习总结)