Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force <input type="file"> to open gallery in mobile

Tags:

html

asp.net

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

like image 496
Lucas Avatar asked Mar 27 '17 18:03

Lucas


People also ask

How do you make an input file only accept pictures?

Solution with HTML attributes But it is possible to restrict the file types to only images, or certain image file extensions. To achieve this, you need to use the HTML accept attribute. This attribute is only used with <input type="file"> and serves as a filter to select file inputs from the file input dialog box.

How does HTML input type file work?

The input element, having the "file" value in its type attribute, represents a control to select a list of one or more files to be uploaded to the server. When the form is submitted, the selected files are uploaded to the server, along with their name and type.


2 Answers

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)

like image 131
Alan Tsai Avatar answered Oct 04 '22 09:10

Alan Tsai


just use simple method to open gallery in mobile

  <input type="file" id="fileProfile2" name="fileProfile2"  accept="image/png,image/jpeg" capture="filesystem">
like image 42
ravi Avatar answered Oct 04 '22 10:10

ravi