I'm sending video and audio files from my Android application to Wampserver, some of these can get quite large and I tend to get OutofMemory issues when the file is approximately over 1MB in size.
I convert each file individually into a byte stream. I think the byte stream is too large hence the OutofMemory.
How can I stop this error from occurring?
Look at this example:
Uploading files to HTTP server using POST on Android.
Using the link Maxium suggested here:
Uploading files to HTTP server using POST on Android.
I then found this Out of Memory error in android to fix the error.
Replace:
while (bytesRead > 0)
{
outputStream.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
with:
while (bytesRead > 0){
bufferSize = Math.min(bytesAvailable, maxBufferSize);
byte byt[]=new byte[bufferSize];
fileInputStream.read(byt);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
outputStream.write(buffer, 0, bufferSize);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With