4 Replies Latest reply on Aug 2, 2013 10:09 AM by philmodjunk

    Include button to download/copy file

    DK

      Title

      Include button to download/copy file

      Post

           My apologies if this question is trivial or stupid - I'm completely new to FileMaker, and have inherited a FM project with an urgent change request.

           I have a table layout with a portal widget that lists OS files related to a database record.  These file names and paths are stored in another table, but the files themselves are on another network computer.  I want to add a button or link to each portal row, which will allow the user to download the file listed in the row to their local hard drive.  I think I've figured out how to put a button in the portal, and the button's Open URL function almost does what I want, but I need a way to copy the file to a local drive, not open it in another program.

           If I could shell out to the OS command line, I could probably write a command to do this.  From what I can tell, though, the closest I can come to that is using Send Event for Windows machines, and Perform AppleScript on Macs.  (Most of the users are on Macs, but I've only ever coded for PCs and web apps.)

           So, my questions are:

             
      1.           Is this the right approach, or is there something (hopefully) easier that I'm missing?
      2.      
      3.           If this is the right way to go, is there a platform-independent approach?
      4.      
      5.           This project is configured as a FileMaker front end with a MySQL back end.  Currently, each user needs to have a copy of the .fmp12 file, have the proper DSN set up to the MySQL server, etc.  Most users use Macs, but we'll be migrating to a single file on a Windows FileMaker Server, with each user having a client to access it.           
                         
        1.                     If there's an unavoidable Windows-Mac duality here, will it be sufficient to use the windows approach on the server, and let the clients just retrieve their info from the server, no matter what platform they're using?
        2.                
        3.                     When executing the copy to the local machine, will I need to do anything special so that it doesn't just copy it to the FM server (the data files will be downloaded from a different server)?  I need the files to go to the clients' local drives, not just to the FileMaker server, to which users won't have direct access.
        4.           
             
      6.      
      7.           It's likely that I'll need to use some FileMaker scripting in any event - is there a good introduction to this available?  I've found a couple of reference pages, but nothing along the lines of a tutorial or basic layout of its capabilities and limitations.
      8.      
      9.           Bonus question - to start out, I'm happy just to copy the file to the user's desktop, but eventually they may want to be able to select the target directory for the file copy.  Is there a built-in utility for that?

           Thanks for your time.

      Button_demo.png

        • 2. Re: Include button to download/copy file
          philmodjunk

               You don't really need a plug in for this. It can all be done from FileMaker and without any system scripts.

               If your files were inserted into container fields with the "store a reference" option enabled, you would already have the file paths stored in container fields instead of these text fields and Export Field Contents could then export the files to the local user's comptuer.

               But since you have the file paths in text fields, a scritp can use Insert File to insert the file into a container field, then use export field contents to copy the file from the container field to the user's desktop or other specified location. This is made possible through assigning the file path to a variable that is then used in the insert and export scripts steps to specify the name and location of the file.

               But I see a potential problem here: "the files themselves are on another network computer."

               The file paths that you show look like paths to the local computer's C: drive. They do not appear to be valid file paths from the local user's computer to the folder on the "other network computer". The set variable step you use to assign a file path to a variable will need to compute a valid file path from the context of the user's computer. That path is determined by how you mount/map from the user's computer to the shared directory that contains the file in question. And all your users need to map/mount the drive in identical fashion so that the resulting path is the same for every user. Once you have determined that path, you can set up your script step to compute that correct path from the data shown in in your screenshot.

               A possible script:

               Freeze Window
               Go to Layout [select a layout where you've placed the needed container field]
               Set Variable [$Path ; value: compute file path to file here]
               Insert File [YourTable::YourContainerField ; $Path ]
               Set Variable [$Path ; value: "file:" & Get ( DesktopPath ) & put calc for filename here ]
               Export Field Contents [ YourTable::YourContainerFIeld ; $Path ]

               Q5) this script can be changed to export to any existing directory on the user's computer by changing the calcualtion in the second set variable step. You can also leave out the $Path variable and let the script open a dialog where the user selects the location and file name for the exported file.

               Q3) You can host your database using either FileMaker Server For Windows or for Mac and both Mac and Windows FileMaker Pro clients will be able to access the files. If any of your Clients are changing from Mac to Windows, however, you may need to make some small adjustments to the layouts used.

               To learn more about Container Fields, File Paths, $Path variables and script steps that can use such a variable, see: Exploring the use of a $Path Variable in Scripts

          • 3. Re: Include button to download/copy file
            DK

                 Thanks for the replies!

                 I didn't see anything directly related to my issue in the plugins, but I haven't finished looking at them.  The instructions in the second reply seem doable to me, though.

                 "The file paths that you show look like paths to the local computer's C: drive."  That's true - this was just a dummy layout I threw together to see if I could get the UI components working, using a local file.  For the real app, the files are on a Linux machine somehwere.  I don't think any users will have that linux machine mapped to a drive letter, so I'll have to tell them to do that, or maybe make it happen as part of FileMaker starting up.

                 This would be a lot easier, though, if I could just send an asynchronous ftp/curl/wget command to the OS command line; I gather there's really no way to do that?

                  

                 Alternatively, is there a way to embed a URL hyperlink instead of a button, so the user could just right-click and save-as to get the file?

            • 4. Re: Include button to download/copy file
              philmodjunk

                   Open URL might work for that ftp command try and let me know if it works.