0

I am facing browser crash while sending base64 image data from one HTML page to another HTML page. So, I want to reduce this base64 string and store it to another variable and then I want to pass that variable.

So how do I reduce base64 image data in JavaScript?

Tony Hinkle
  • 4,566
  • 7
  • 20
  • 33
Bikshu s
  • 337
  • 4
  • 10
  • _"while sending base64 image data from one html page to another html "_ ? How do you do that ? – Rayon Jul 30 '16 at 09:34
  • `reduce this base64 string` - what do you mean? make it smaller? – Jaromanda X Jul 30 '16 at 09:36
  • try using `localStorage` or `sessionStorage` – Jaromanda X Jul 30 '16 at 09:37
  • now i am sending "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkK" through URL from one html page to other html page.... I want to send it as a varible through javascript – Bikshu s Jul 30 '16 at 09:46
  • @Bikshus by url you mean a `GET` query string? – Iceman Jul 30 '16 at 09:54
  • yes..Like this..window.location.href='canvas4.html#id='+a+'&src='+base64stirng; – Bikshu s Jul 30 '16 at 10:01
  • if you're going to do it that way use encodeURIcomponent(base64stirng) then grab the query var base64string = decodeURIcomponent(getParameterByName('src')) http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript – Leroy Thompson Jul 30 '16 at 10:03
  • Thanks @Jaromanda X I have achieved this with sessionStorage.setItem(); and sessionStorage.getItem(); – Bikshu s Jul 30 '16 at 10:34

1 Answers1

0

To reduce a string you should reduce the image itself. If you cannot control size of images (for example, if it is an image which is uploaded by the user) then you should consider another way to send images.

For example, you can use POST instead of GET (query string). Either use <form> tag or post via javascript (example: JavaScript post request like a form submit).

Community
  • 1
  • 1
user2316116
  • 6,485
  • 1
  • 19
  • 34