Sto provando a convertire un file dalla sdcard in Base64 ma sembra che il file sia troppo grande e ottengo un OutOfMemoryError.Convertire un file (<100Mo) in Base64 su Android
Ecco il mio codice:
InputStream inputStream = null;//You can get an inputStream using any IO API
inputStream = new FileInputStream(file.getAbsolutePath());
byte[] bytes;
byte[] buffer = new byte[8192];
int bytesRead;
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
while ((bytesRead = inputStream.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
} catch (IOException e) {
e.printStackTrace();
}
bytes = output.toByteArray();
attachedFile = Base64.encodeToString(bytes, Base64.DEFAULT);
Esiste un modo per andare in giro alla OutOfMemoryError mentre il deposito della stringa attachedFile?
Usa questo codice sarà utile https://stackoverflow.com/a/47572643/3505534 – R2R