'Is base64 encoded image uploading a bad practice?

Is there a problem to use base64 encoding to upload (only upload) the image to the server? Considering the common image size of around 1-2 MB, not icon sized images. Is this a bad practice? Should it always use form data for image uploading?

The image would be sent inside a POST body (JSON content type) together with other data, like:

// POST /signup
{
  email: '[email protected]',
  password: '12345678',
  name: 'Example Name',
  picture: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAA...',
}

Once in the server, it would be sent to AWS bucket and get served as a binary file, not a base64 encoded string.



Solution 1:[1]

The generally accepted result of Base64 encoding a binary image is a result roughly 30% greater than the original. If the server limit is 2MB, you're effectively limited to a 1.4MB image as you're increasing it via encoding. Base64 isn't a compression method, it's just a method of getting binary data to a server over HTTP.

If you have control of the server, make it accept gzip compressed binary data instead, or if you can put the image somewhere, send the url of it in the request and the server can download it.

Solution 2:[2]

Bas64 encoded images are good practice for a small size (KB) images. For bigger size image you will get size errors probably.

Although if you want to use (MB) size images, i suggest to pass them as a thumbnail.

Thumbnails are reduced-size versions of pictures or videos, used to help in recognizing and organizing them, serving the same role for images as a normal text index does for words

https://www.npmjs.com/package/image-thumbnail

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 codebrane
Solution 2 bembas