Big video to string base64 causes outofmemoryerror

拈花ヽ惹草 提交于 2019-12-12 13:17:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!