File Upload and capture response

Hi Scott, sorry for the delay. Here is a sample code for uploading the files directly from code instead of HTML. You can adapt it to your situation, in this sample I'm getting the email and file values from existing controls in the form (I used the same names (id) used in the FileUploadSample, but you might have different ones). I'm also reporting the returned status code and content in a WebButton1 and WebMemo1 controls. You can of course adapt to put those values in variables and process them.




procedure TForm1.WebButton1Click(Sender: TObject);
var
  formData: JSValue;
  xhr: TJSXMLHttpRequest;


  procedure _load;
  begin
    WebButton1.Caption := IntToStr(xhr.Status);
    WebMemo1.Lines.Text := xhr.responseText;
  end;


begin
  asm
    formData = new FormData();
    formData.append('fileUpload', document.getElementById('exampleFormControlFile1').files[0]);
    formData.append('emailAddress', document.getElementById('exampleInputEmail1').value);
  end;


  xhr := TJSXMLHttpRequest.new;
  xhr.open('POST', 'http://localhost:2001/tms/sparkle/upload');
  xhr.addEventListener('load', @_load);
  xhr.send(formData);
end;