5

I'm trying to create a reusable directive in my app that allows for files to be encoded as base64 then uploaded via JSON.

I haven't seen my resources on the web talking about this approach. I've mostly only been able to find Angular file uploads via form data.

Can anyone shed some light on this topic?

Mike Fisher
  • 913
  • 3
  • 13
  • 27

1 Answers1

2

This link may prove interesting. Basically he state that Base64 encoded data is 33% larger and takes longer to process than binary.

htmltrocks has an interesting article regarding integrating the canvas element into your App. It shows use of the HTML5 canvas toDataURL() method which converts to Base64.

See also: How to convert image into base64 string using javascript

Community
  • 1
  • 1
Mick Cullen
  • 9,214
  • 3
  • 21
  • 17
  • 3
    The 33% increase should be taken with a pinch of salt. If you have a website that uses gzip compression the overhead drops to 9%. Plus if that data can be inlined it saves additional requests. The other interesting thing is that Base64 is claimed that it *may* be slower. Its important to realise that often the quickest development solution is the best, developer time is more valuable than a few ms in most cases. – Phil Hannent Jan 18 '15 at 11:46
  • If Base64 data is 33% larger, then what is the approach to send the file to server? Please suggest – sasi Sep 11 '19 at 06:20