i am trying to upload a file to Amazon S3 using HttpUrlConn开发者_StackOverflow中文版ection and the put method.
outputStream = new DataOutputStream( connection.getOutputStream() );
bytesAvailable = fileInputStream.available();
int current = 0;
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
// Read file
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0)
{
outputStream.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
current+=bytesRead;
}
is this the proper way to use the buffer to output data? It all works great for smaller files but when i try to upload something larger it says
02-11 19:04:38.718: INFO/dalvikvm-heap(15385): Grow heap (frag case) to 9.204MB for 3143696-byte allocation
what am i doing wrong? any help is highly appreciated, thank you.
精彩评论