Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Base64 image upload VS Binary image upload?

I want my mobile application to be able to upload an image to my server, in my case it's a Rails 3.2.11 with nginx.

I read alot about Base64 encoding on client side and then decoding on the server side.

Why not just use binary upload with multipart headers on the http request?

Are the any pros / cons for each technic?

like image 527
Danpe Avatar asked Feb 09 '13 12:02

Danpe


People also ask

What is the difference between Base64 and binary?

Base64 image representation can be directly placed within html to render an image. Binary takes up less space. And benefits from greater network effects and standardization. E.g. if you want to use amazon simple secure storage S3 you have to store a binary file.

Why use Base64 instead of binary?

Also, textual media may reject certain binary values as non-text. Base64 encoding encodes binary data as values that can only be interpreted as text in textual media, and is free of any special characters and/or control characters, so that the data will be preserved across textual media as well.

Do Base64 images load faster?

Although Base64 is a relatively efficient way of encoding binary data it will, on average still increase the file size for more than 25%. This not only increases your bandwidth bill, but also increases the download time.

Does Base64 encoding reduce image quality?

Encoding to/from Base64 is completely lossless.


2 Answers

Base64 converts your data to an ASCII representation of the binary data. It allows you to embed your data in text streams such as JSON for example. Base64 increases the size of the data transferred by 33%.

multipart/form-data is the standard way of transferring binary data in HTTP requests. It allows you to use specific encodings / content types for each part you'd like to transfer. In my opinion, you should stick to multipart uploads unless you have specific requirements or device/SDK capabilities.

like image 200
Jef Avatar answered Oct 11 '22 02:10

Jef


'Why not just use binary upload with multipart headers on the http request?' indeed why not ;)

Base64 image representation can be directly placed within html to render an image.

Binary takes up less space. And benefits from greater network effects and standardization. E.g. if you want to use amazon simple secure storage S3 you have to store a binary file. You can't store a string you would need a key/value store e.g. redis.

like image 20
Harry Moreno Avatar answered Oct 11 '22 03:10

Harry Moreno