Select to view content in your preferred language

Why is the Image question type allowing any file type to be attached?

2553
5
Jump to solution
02-01-2022 05:24 PM
Gerhard
Regular Contributor

I want to allow users to capture or attach only images in a survey. However, the image question type appears to be accepting any file type in the field app and only images (as expected) in the web form. The question uses a multiline appearance and method=camera,browse in the body::esri:style column. Please see the attached table for full configuration.

I've tried using body::accept to constrain file type, but doing so removes the camera capability from the field app (but not the web form). I've tried extensions (.gif, .jpg, .png) and MIME types (image/gif, image/jpg, image/png) in body::accept with the same result.

Best,

Gerhard
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Hi @Gerhard,

Thanks, that makes sense. When using the Files app on iOS unfortunately the file picker does not currently filter only for image file types (when you use an image question). There is a limitation with the Files app that current impedes this working properly, however when using Photos gallery option it only displays images. Note this works on Windows and Android OS when using an image question and file picker.

Good news is that you can use a constraint to check if the file attached was a .jpg (or any other format). Add a hidden question to your survey, and reference the image question in the calculation column. Then add a regex() constraint with the string in it that you want to check for. When the user attaches a file and tries to submit, the constraint error will be displayed in a pop-up if the file type doesn't match. You can customize the constraint message as needed. Below I selected a .png file, and therefore got a error message:

PhilipWilson_1-1644205863002.png

ios_screenshot.jpg

Hope this helps.

Regards,

Phil.

View solution in original post

5 Replies
by Anonymous User
Not applicable

Hi @Gerhard,

Which version of the field app are you using, and on what OS version (iOS, Android or Windows)?

Also what is the workflow and buttons being selected, there are different behaviors and limitations with file types on different OS. If you are on iOS there are two options, the gallery or files app, if you use files app you can attach other types, unfortunately we can not control this due to the way the files app works with Survey123.

Regards,

Phil.

Gerhard
Regular Contributor

Hi @Anonymous User,

I'm using version 3.13.246 on iOS 15.2.1. I have also tested this with the 3.14.232 RC2 build on the same device.

The workflow is: Image question type > Select image from? > Files > Files app. Could it be possible to validate the file type in the form once a file has been uploaded using a constraint

Best,

Gerhard

Best,

Gerhard
0 Kudos
by Anonymous User
Not applicable

Hi @Gerhard,

Thanks, that makes sense. When using the Files app on iOS unfortunately the file picker does not currently filter only for image file types (when you use an image question). There is a limitation with the Files app that current impedes this working properly, however when using Photos gallery option it only displays images. Note this works on Windows and Android OS when using an image question and file picker.

Good news is that you can use a constraint to check if the file attached was a .jpg (or any other format). Add a hidden question to your survey, and reference the image question in the calculation column. Then add a regex() constraint with the string in it that you want to check for. When the user attaches a file and tries to submit, the constraint error will be displayed in a pop-up if the file type doesn't match. You can customize the constraint message as needed. Below I selected a .png file, and therefore got a error message:

PhilipWilson_1-1644205863002.png

ios_screenshot.jpg

Hope this helps.

Regards,

Phil.

Gerhard
Regular Contributor

Thanks @Anonymous User, that's really useful insight and a simple solution.

Best,

Gerhard
Gerhard
Regular Contributor

Multiple image attachments and file types need to be accepted in the form so I used this regex to validate the attachments:

regex(.,'^(?:[0-9a-zA-Z\._-]+\.(?:png|PNG|gif|GIF|jp[e]?g|JP[E]?G),*)+$').

It was interesting to discover the Survey123 field app renames and formats attachments into a string like this:

media-20220209-044727.jpg,media-20220209-174736.png,media-20220209-044727.gif

The web form doesn't rename files so the string looks more like this:

IMG_4EE7E891D341-1.jpeg,Screen_Shot.png

Best,

Gerhard