Null Pointer Null Pointer - 9 months ago 59
AngularJS Question

Image not saving properly in blob field (Angular App to Python)

I'm trying to save image from

angular App
blob field in
but Image not saving properly.

This is how I'm converting image to byte-array

var reader = new FileReader();
reader.onload = function(e){
var arrayBuffer = reader.result;
$scope.ImageArr = new Uint8Array(arrayBuffer);

I'm getting this
in python having key-value list, then I get values from it like this

userByte =bytearray(ImageArr.values())

But when I save this
in mysql's Blob field, it saves some bytes there but that is not a proper image.

Any guesses what I'm doing wrong or what I'm missing?? Any kind of help will be appreciated.

Edited: (Updated code that worked for me)

First I convert my image to base64 through this code

reader = new FileReader();
reader.onloadend = function(e) { //callback after files finish loading
var img =;
$scope.ImageArr = img;
reader.readAsDataURL($scope.UserImage); //once defined all callbacks, begin reading the file

then In python i encoded it in bytes like this


This works perfectly fine for me.

Answer Source

for as a hint you can save base64 image easily rather than byte arrays