Here is your problem:
Base 64 encoded string includes characters like /
and +
, which as you can imagine have special significance if the request content type is said to be application/x-www-form-urlencoded
. So, with your current code, +
sign gets decoded as a space, and combinations like \n
get interpreted as control characters such as line feed, new line etc.
All you have to do is encode dataURL
to make sure it is safe for use as a parameter value. This is as simple as using the encodeURIComponent
method.
i.e. var data = 'image=' + encodeURIComponent(dataURL);
Hope this helps.