I sometimes get an OutOfMemoryError when posting a large file in Android. This is the code I\'m using. Am I doing something wrong?
HttpURLConne
If you do it like that, the whole POST must be buffered in memory. This is because it needs to send the Content-Length header first.
Instead, I think you want to use the Apache HTTP libraries, including FileEntity. That will let it figure out the length before reading the file. You can use this answer as a starting point. But the second parameter to the FileEntity constructor should be a mime type (like image/png, text/html, etc.).