Great video in base64 string causes outofmemoryerror

I need to send the video to the webservice in .net, im send the base64 encode string if the video is about 2 MB or 6 seconds 7 seconds everything is fine, but when the more serious reasons are outofmemoryerror when I do Bas.encode [byte []);

This is my code:

videoPath = getRealPathFromURI(fileUri); File tmpFile = new File(videoPath); in = null; in = new BufferedInputStream(new FileInputStream(tmpFile)); bos = new ByteArrayOutputStream(); long tamano = tmpFile.length(); int iTamano = (int) tamano; byte[] b = new byte[iTamano]; int bytesRead; while ((bytesRead = in.read(b)) != -1) { bos.write(b, 0, bytesRead); } ficheroAEnviar = bos.toByteArray(); try { strBase64 = Base64.encode(ficheroAEnviar); } catch (Exception e) { correcto = false; e.printStackTrace(); } 

Failure in this line: strBase64 = Base64.encode (ficheroAEnviar);

+3
source share
1 answer

You cannot do that. Memory is a problem in android. You have to split the video in several parts, encode each part, send it (I think you want to send it via WS or something else) and recompile it as intended.

+4
source

All Articles