问题
i need to send video to webservice in .net, im send a string base64 encode, if the video its about 2MB or 6 o 7 seconds all its ok, but when is more heavy causes 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();
}
Crash in this line: strBase64 = Base64.encode(ficheroAEnviar);
回答1:
You cannot do like this. The memory is an issue in android. You should split the video in few parts, encode each part, send it (I think you want to send it over a WS or something) and recombine it on destination.
来源:https://stackoverflow.com/questions/11775036/big-video-to-string-base64-causes-outofmemoryerror