17

I want to make my input to only accept files from gallery instead of allowing the user to open the camera.
How can I achieve it?

ASP.NET

<asp:FileUpload ID="filGallery" runat="server" AllowMultiple="true" />

HTML 5

<input type="file" id="filGallery" multiple="multiple" />

The behaviour I want is similar to the one found in iOS 8 or less, where input with multiple files enabled couldn't open the camera

Lucas
  • 534
  • 1
  • 10
  • 29

2 Answers2

13

I don't think there is a way to force using gallery - current trend is more on using camera (and suggesting using front or back) rather than disabling it.

However, there is a similar question on SO (but focus on type of capture) where that answerer has pointed to some ways of input attribute you may try out:

original SO: https://stackoverflow.com/a/40512470/2564920

More detail test he has done regard to the mobile capture: https://addpipe.com/blog/correct-syntax-html-media-capture/

A test page which you can try out: https://addpipe.com/html-media-capture-demo/

specifically one setting which is

<input type="file" accept="image/*" capture="filesystem">

looks promising - but probably won't work (since this syntax is deprecated and capture attribute in newer spec is used to say you want to use camera - choosing between front or back camera source)

Arun Kumar Mohan
  • 11,517
  • 3
  • 23
  • 44
Alan Tsai
  • 2,465
  • 1
  • 13
  • 16
  • 3
    Yeah, didn't work.. Well, I hope the spec changes, would be good to have a way to do it... Thanks anyway, +1 – Lucas Mar 28 '17 at 12:07
1

just use simple method to open gallery in mobile

  <input type="file" id="fileProfile2" name="fileProfile2"  accept="image/png,image/jpeg" capture="filesystem">
Ravi
  • 324
  • 2
  • 10
  • 1
    This doesn't work. The 'accept' attribute that you provided is only stating that png and jpeg are the file types accepted. – Tray Fleary Mar 11 '20 at 19:57
  • @TrayFleary It worked on my side please check yours. – Ravi Mar 12 '20 at 13:29
  • 2
    No, it doesn't work. Accept is just a limitation on mime-types allowed, but device is opening system pop-up and gives the option to choose camera as well – Lowlo Jan 28 '21 at 08:50