im sending videos to webservice and works ok with videos less than 10MB, if the video is about 12MB give me outofmemoryerror:
This is my code:
FileInputStream fileInputStream = new FileInputStream(fichero);
int bytesAvailable = fileInputStream.available();
int maxBufferSize = 1024 * 1024 * 2;
int bufferSize = Math.min(bytesAvailable, maxBufferSize);
byte[] buffer = new byte[bufferSize];
int bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0) {
dos.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
// nuevos
byte byt[] = new byte[bufferSize];
fileInputStream.read(byt);
// nuevos
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
// esto es nuevo
dos.write(buffer, 0, bufferSize);
// ya no es nuevo
}
I think it is because im buffering all video, but i dont know how to send this without saviing in buffer.
This is the stack error:
08-31 08:54:20.925: E/AndroidRuntime(18476): Caused by: java.lang.OutOfMemoryError
08-31 08:54:20.925: E/AndroidRuntime(18476): at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)
08-31 08:54:20.925: E/AndroidRuntime(18476): at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:216)
08-31 08:54:20.925: E/AndroidRuntime(18476): at org.apache.harmony.luni.internal.net.www.protocol.http.RetryableOutputStream.write(RetryableOutputStream.java:60)
08-31 08:54:20.925: E/AndroidRuntime(18476): at java.io.DataOutputStream.write(DataOutputStream.java:99)
08-31 08:54:20.925: E/AndroidRuntime(18476): at com.reparalia.movilidad.AdjuntarFicheros$SubeFichero.doInBackground(AdjuntarFicheros.java:702)
08-31 08:54:20.925: E/AndroidRuntime(18476): at com.reparalia.movilidad.AdjuntarFicheros$SubeFichero.doInBackground(AdjuntarFicheros.java:1)
The 702 line is dos.write(buffer, 0, bufferSize);
There are any way to send the video?Thanks