Python / Django Fails At Decoding File Encoded As Base64 By Javascript
I'm using this, in react, to base64 encode an image file: fileToBase64 = (filename, filepath) => { return new Promise(resolve => { var file = new File([filename],
Solution 1:
You will have to strip the base64 string from the prefix added by javascript.
The prefix is sth like data:{type};base64,{actual-base64-string-follows}
In php, where I had same issue, I tested if string starts with "data:" prefix and I strip it from start of string up to the position of the ; (semicolon) plus 8 characters (to catch the final ";base64,").
Then you can use python to decode the base64 string remaining as it is now a valid base64 string.
Post a Comment for "Python / Django Fails At Decoding File Encoded As Base64 By Javascript"