如何将每个文件(不仅是位图)编码为base64?

时间:2018-11-14 08:38:42

标签: android encoding base64

我正在寻找解决问题的方法,该方法与将文件编码到base64并发送到我的服务器有关。我找到了一种在Internet上对位图进行编码的解决方案:

public static String bitmapToEncodedString(Bitmap bitmap) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] imageBytes = baos.toByteArray();
    return Base64.encodeToString(imageBytes, Base64.NO_WRAP);
}

,但是此解决方案只能用于位图,而pdf文件或doc或smth之类的呢?也许有人对我的问题有很好的解决方案?如果您能解决我的问题,我会很高兴。

0 个答案:

没有答案