TWebCamera, XDara and error "The string to be dec"

Hi!


I've made a windows with a TWebCamera component that adds a picture to the XData structure. The problem I encounter is this:

New.pas:271 Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
    at Object.wdsPobudaAfterApplyUpdates (http://localhost:8000/Okolje24/Okolje24.js:63460:39)
    at Object.cb [as FAfterApplyUpdates] (http://localhost:8000/Okolje24/Okolje24.js:222:26)
    at Object.DoAfterApplyUpdates (http://localhost:8000/Okolje24/Okolje24.js:37121:49)
    at Object.ResolveUpdateBatch (http://localhost:8000/Okolje24/Okolje24.js:36772:12)
    at Object.cb [as FOnResolve] (http://localhost:8000/Okolje24/Okolje24.js:222:26)
    at Object.CheckBatchComplete (http://localhost:8000/Okolje24/Okolje24.js:48829:58)
    at Object.cb [as FOnLoad] (http://localhost:8000/Okolje24/Okolje24.js:222:26)

The code I use to upload the image is after the ApplyUpdate (So I get the Id of the record):



procedure TfrmNew.wdsPobudaAfterApplyUpdates(Sender: TDataSet; Info: TResolveResults);
begin
  UpdatePicture;
  Result := wdsPobuda.FieldByName('Id').AsInteger;
  ModalResult := mrOk;
end;





procedure TfrmNew.UpdatePicture;
var
  xhr: TJSXmlHttpRequest;


  function Base64ToArrayBuffer(str: string): TJSArrayBuffer;
  var
    BufView: TJSUInt8Array;
    BinaryString: string;
    I: Integer;
  begin
    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);
  end;


begin
  xhr := TJSXMLHttpRequest.new;
  xhr.open('PUT', connServer.URL+'/'+string('pobuda('+wdsPobuda.FieldByName('Id').AsString+')/Slika'));
  xhr.send(Base64ToArrayBuffer(camMain.SnapShotAsBase64));
end;


I checked the string and I don't know how to resolve the error, please help.


One note. If I add a TWebImageControl and transfer the image from camera to the image, then it works. 


I did it this way:

    imgCam.URL :=  camMain.SnapShotAsBase64;



Then I slightly modified the update Image code

  xhr.send(Base64ToArrayBuffer(imgCam.Base64Image)); // Before it was: camMain.SnapShotAsBase64));


This is enough form my purposes, i'm just informing you about this issue.


camMain.SnapShotAsBase64 includes the data format specifier, i.e. not just the data.

If you want to directly use camMain.SnapShotAsBase64 , delete the first part of the base64 string that is the data format specifier.