Jump to content


Photo

input type="file" not working on iOS9 (iPad)


  • Please log in to reply
3 replies to this topic

#1 markus_ja

markus_ja
  • Members
  • 319 posts
  • LocationAustria

Posted 03 May 2016 - 08:57 PM

Hello,

 

I want to access the camera on iOS. And since iOS6, that is supported by the browser.

Using <input type="file" access="image/*" capture="camera"> works fine on my desktop browser, but not on my iPad.  The input box is not shown as file input box.

I also tried some other pages, and there it works, like here: http://jsfiddle.net/4WHw5/1/

It seems I am missing something.

 

This is my code:

edtFileUpload.InputType := itFile;
w3_setAttrib(edtFileUpload.Handle, 'accept', 'image/*');
w3_setAttrib(edtFileUpload.Handle, 'capture', 'camera');

Can anybody help?


  • AlexissNag and pagwag like this

#2 ron

ron
  • Members
  • 31 posts

Posted 06 September 2016 - 10:32 PM

I have the same problem..is there a workaround?



#3 markus_ja

markus_ja
  • Members
  • 319 posts
  • LocationAustria

Posted 07 September 2016 - 10:25 AM

You don't have to use the TW3EditBox. You have to use "clean" <input> tag, without all the default attributs.

 

I created a simple wrapper:

TMyInputFile = class(TW3CustomControl)
  private
    procedure SetAccept(aValue: string);
    procedure SetCapture(aValue: string);
  protected
    function MakeElementTagObj: THandle; override;
    procedure StyleTagObject; override;
  public
    procedure OpenDialog;
    property Accept: string write SetAccept;
    property Capture: string write SetCapture;
  end;

{ TMyInputFile }

procedure TMyInputFile.StyleTagObject;
begin
  //prevent default
  w3_setAttrib(Handle, 'type', 'file');
end;

function TMyInputFile.MakeElementTagObj: THandle;
begin
  result := w3_createHtmlElement('input');
end;

procedure TMyInputFile.SetCapture(aValue: String);
begin
  w3_setAttrib(Handle, 'capture', aValue);
end;

procedure TMyInputFile.SetAccept(aValue: String);
begin
  w3_setAttrib(Handle, 'accept', aValue);
end;

procedure TMyInputFile.OpenDialog;
begin
  Handle.click();
end;

Usage:

//Image File Upload
  _myFileOpenDialog := TMyInputFile.Create(divViewGeneral);
  _myFileOpenDialog.Visible := false;
  _myFileOpenDialog.Accept := 'image/*'; // or '.png, .jpg'
  _myFileOpenDialog.Capture := 'camera';

  _myFileOpenDialog.Handle.addEventListener('change',
    procedure(e: Variant)
    var
      fileReader: JFileReader;
      fileList: JFileList;
    begin
      fileList := JFileList(e.target.files);
      if fileList.length > 0 then
        _imageFile := fileList.item(0)
      else
        _imageFile := nil;

      if Assigned(_imageFile) then
      begin
        fileReader := JFileReader.Create;
        fileReader.onload :=
          function(event: JEvent): Variant
          begin
            imgRecipe.Url := Variant(event.target).result;
            result := true;
          end;

        fileReader.readAsDataURL(_imageFile);

      end;
    end, false);


#4 ron

ron
  • Members
  • 31 posts

Posted 07 September 2016 - 07:22 PM

thanks ..i will try that..






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users