3

I'm use CEF 3.2454.1344.g2782fb8 (Chromium 45.0.2454.101) in my project in Delphi 10.1. (I have to use a fairly old version of CEF/Chromium for backwards compatibility with WinXP). So my question is: when I click "Upload" button on any site I get a open file dialog, and have to choose a file to upload. It is possible to do not show this dialog to user, but give CEF some pre-assigned file instead?

UPDATE: I've tried to do this via OnFileDialog, it's exactly I need: after clicking on "Upload" button I got a file shown on a web page, but Chromium instantly crashed after this. Any ideas?

procedure TMainForm.crm_asFileDialog(Sender: TObject;
  const browser: ICefBrowser; mode: TCefFileDialogMode;
  const title, defaultFilePath: ustring; acceptFilters: TStrings;
  selectedAcceptFilter: integer; const callback: ICefFileDialogCallback;
  out Result: Boolean);
var
  file_list: tstringlist;
begin
  file_list := tstringlist.Create;
  file_list.Add
    ('https://testsite.com/my_image.jpg');
  callback.Cont(0, file_list);
  file_list.Free;
  Result := true;
end;

UPDATE 2: HTML code of a form

<form method="post" enctype="multipart/form-data">
  <input accept="image/*" type="file" name="file1" />
  <input accept="image/*" type="file" name="file2" />
  <input accept="image/*" type="file" name="file3" />
</form>
Red October
  • 487
  • 1
  • 8
  • 27
  • 1
    This has nothing at all to do with CEF3. That's just how that site is implemented. I suspect that the real issue is that you have chosen the wrong tool to automate uploading files to this web service. A browser is meant to be used by a human. – David Heffernan Jun 19 '18 at 09:31
  • @DavidHeffernan why? There is many tools based on Chromium to automation some actions of users. – Red October Jun 19 '18 at 09:37
  • 1
    Your code is doing it right (just minor things to fix are missing `try..finally` block and passing `selectedAcceptFilter` to that callback method). But that should not be problem. There might be a bug, but still, could you share the HTML input element code with which your CEF crashes? – Victoria Jun 19 '18 at 12:10
  • 1
    I test you code with local files and all work fine. I have CEF 3.2454.1342. Maybe the problem is that you are trying to download a non-local file – Vasek Jun 19 '18 at 12:28
  • @Victoria I've added a form code, it's pretty simple :) Also I've tried to upload a local file as suggested Vasek - and it works fine to me. – Red October Jun 19 '18 at 12:36
  • @Vasek, yes, local file works fine to me! – Red October Jun 19 '18 at 12:37

0 Answers0