Android Image upload/download with Base64 into JSON causes Out of memory error : <p>I currently encode and decode images to Base64. I overcame the initial issue with OOM's with the use of streams to encode the images into strings.</p>

<p>My issue now is that I cannot fathom how to add multiple Base64 encoded strings for multiple resolutions images (5620 x 3747 - 4.92MB or 3264 x 1836 - 1.35MB) to a JSON Object via Gson. Currently Gson throws an OOM exception only with 2 Base64 Strings from a 5312 x 2988 - 4.95 MB Image.</p>

<p>I understand that android may only be able to spare 16/20Mb per application, so this conversion must be way over the limit.</p>

<p>How can I write the Base64 String in a stream to a JSON object that will contain the specific values needed to post into my server?</p>

<p>Would it be easier to change my server to accept a Multi-Part request instead of a JSON based POJO with multiple Base64 Strings? I currently use Volley and there isn't an official Multi-Part Request as well as IO streaming.</p>

<p>If it's a matter of compression, how much compression should I apply to the image before encoding into a Base64 String? I ideally want to lose barely any quality but have optimal compression levels.</p>

<p><strong>Bit more Information</strong></p>

<p>I am uploading multiple different resolution images as it is a test for compatibility. For example, all the images that I am sending up have been taken on low resolution and extremely high resolution devices as my App relies on these images for functionality. I am trying to prove that any image (to a certain extent, mainly images captured on mobile devices) can be handled by my application.</p>

<p>I understand that some images may be so large that by loading them into memory will cause exceptions. This is something I will try and handle later.</p>

<p>In some cases the images that will be uploaded can span from 1 to 200.</p>

<p>I'm trying to look for the most optimal solution that will scale well.</p>
