Base64 and DB


working on a project that takes an image and save it to the DB I noticed that it is saved in a strange format. It's working, I'm just curious.

Using this code:

procedure TfrmNew.UpdatePicture;
  xhr: TJSXmlHttpRequest;
//  slika: string;

  function Base64ToArrayBuffer(str: string): TJSArrayBuffer;
    BufView: TJSUInt8Array;
    BinaryString: string;
    I: Integer;
    BinaryString := window.atob(str);
    Result := TJSArrayBuffer.New(Length(BinaryString));
    BufView := TJSUInt8Array.New(Result);
    for I := 0 to Length(BinaryString) - 1 do
      BufView := TJSString(BinaryString).CharCodeAt(I);

  xhr :=;'PUT', connServer.URL+'/'+string('pobuda('+wdsPobuda.FieldByName('Id').AsString+')/Slika'));
  xhr.send(Base64ToArrayBuffer(StringReplace(camMain.SnapShotAsBase64, 'data:image/png;base64,', '', [])));

The input string is like this:


but in the DB is saved like this:

‰PNG  IHDR€à5ÑÜä IDATx^̽YnYrv¾)3ï½U=Åf7AX4m

Is this correct?

Note: The strings are of course truncated to first 40 chars for demo purposes

What data type is your server expecting?

If you expect this to be stored in your DB as base64 string, why trying the conversion to an Int8Array?
Can't you send the base64 string as-is?

I did this based on this forum post:

The code converts the base64 encoded image data to a binary array, so it is normal that the data you look at as base64 string is different from the binary data.
The binary data looks, at least from what I can see as PNG file header correct, a PNG image file starts with header ‰PNG So, I would assume the binary data to be correct? What do you experience as incorrect?