How To Get Attachment File Types


When capturing photos, videos, or sound recordings in SurveyToGo, there is sometimes a need to validate that an attachment has been added to the interview or to check the file type.

This ‘How To’ will show you how to retrieve the file types of the attachments to an interview.


  • Create an array to hold the types of attachments within the interview (or question). This can be done in the advanced scripts as a function or in the start or end script of a question:

var names = GetAttachedFilesNames(); //Get a string of all file names

var arrTypes = [];      //Array to hold all file types

for(var i = 0; i < names.length; i++)


      var type = stringSplit(names[i],'.');     //Split the file names at the '.'

      arrTypes.push(type[1]);                         //Save the file type, second part of split name


  • After this point, you now have an array with all file types for the survey.  If you want only the attachment file types for a specific question you can use the GetAttachedFileNames() overload where you input the question ID.

var names = GetAttachedFilesNames(qID); //Get a string of file names of qID

This array can then be used to validate the existence of certain attachment types within either a specific question of the interview overall. 

For example, you can use the array to confirm that a picture was taken at a given question by comparing the file types in the array to image file types (jpg, bmp, png, gif).


That's It!

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request



Please sign in to leave a comment.