Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending file > 1MB using HTTP POST

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?

like image 377
Neeta Avatar asked May 21 '26 10:05

Neeta


2 Answers

Look at this example:

Uploading files to HTTP server using POST on Android.

like image 52
Maxim Avatar answered May 22 '26 23:05

Maxim


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);
}
like image 30
Neeta Avatar answered May 23 '26 00:05

Neeta