3 Replies Latest reply on Dec 5, 2012 12:00 PM by philmodjunk

    Validating 'Insert Picture' by File Type

    Atkins

      Title

      Validating 'Insert Picture' by File Type

      Post

           Hello,

           I keep coming back to this issue, deciding it's not important enough to spend time on, then coming back again.  I have several fields that are meant to be containers for PDF attachments and I've been using the 'Insert Picture' script to upload the files.  This works simply and effectively, but I'd like to be able to limit the file type to PDF only, not any picture file.  I think to do this I need to be able to read the filename on import, but I don't know if this is possible.

           Reading the file name on import could also be useful such that I could set a variable or field with the actual file name so that when the file is exported I could re-tag it with the original file name.

           Below is the validation script that I tried using.  It should relay my idea of how I think it should work, although it obviously did not work or I wouldn't be here.  Thanks!

            

           Validation =

           ( Right ( Get ( DocumentsPath ) ; 4 ) = ".pdf" ) or ( Right ( Get ( DocumentsPath ) ; 4 ) = ".Pdf" ) or ( Right ( Get ( DocumentsPath ) ; 4 ) = ".PDF" )

        • 1. Re: Validating 'Insert Picture' by File Type
          philmodjunk

               Why would the text from "Get ( documentspath )" ever end in the file extension of the file being inserted into the container field?

               The text returned by this function is the file path to the documents folder on the current computer for the current user account. It won't return the name of the file that you are inserting.

               After the file is inserted into a container field, this calculation will return the file name:

               Let ( [T = GetAsText ( GetValue ( YourTable::containerField ; ValueCount ( ContainerTest::containerField ) ) ) ;
                           L = Length ( T )];
                           Right ( T ; L - Position ( T ; "/" ; L ; -1 ) )
                   )

               It, BTW, will extract the name of a file inserted by any insertion method except "Insert Object" (Found in windows versions older than FileMaker 12) regardless of whether or not "store a reference" was used to insert the file.

               PS. if you are inserting a batch of files from a folder inclosed by the Documents folder, it is possible to parse the list of text returned by Get ( DocumentsPathListing ) to list all files in that folder that end in .PDF.

          • 2. Re: Validating 'Insert Picture' by File Type
            Atkins

                 Yeah, I never would've come up with this formula.  Thanks.

                 I'm not sure what ContainerTest::containerField is though.  Is ContainerTest another field or would I just write pdf::containerField or what?

                 Also, this may seem unnecessary, but does this check to see if "pdf" appears anywhere in the filename or specifically at the end, as an extension would?  Just curious.

                 Lastly, I currently have this formula in the field validation area.  Does it need to be run as a script after the file has been uploaded and the record submitted, or can I leave it in the validation area?

                 Thanks for the clarification.

            • 3. Re: Validating 'Insert Picture' by File Type
              philmodjunk
                   

              ContainerTest::containerField

                   You would substitute a reference to your container field in place of that reference--which was a reference to a container field in the test file where I verified that this calculation works.

                   This is the regular filename for the file so .PDF will be the last 4 characters of the file name if a PDF was inserted.

                   If you wanted to make this a validation calculation, you could use:

                   Right ( Let ( [T = GetAsText ( GetValue ( Self ; ValueCount ( Self ) ) ) ;
                               L = Length ( T )];
                               Right ( T ; L - Position ( T ; "/" ; L ; -1 ) )
                          ) ; 4 ) = ".PDF"