5 Replies Latest reply on Mar 31, 2010 12:36 PM by stewieK

    Import images into FM from an xml http data source

    stewieK

      Title

      Import images into FM from an xml http data source

      Post

      Long story short I have mainly textual data stored on a server in a mysql data base and I want to import it into FM.

       

      So I pull the data from the DB and with PHP I create an FM friendly XML file,

      which is then pulled into FM via an HTTP import...

      Cool, easy... still with me?... good.

       

      The trick is I have a few images and pdf files that I need to import into the record at the same time as the rest of the data.

      They are stored in a directory on the server seperate to the textual data, but the file reference (URI) is in the XML record i'm sending down.

       

      Now I would have thought that if I gave the container field, in FM, the file reference to the image I want it to download, during the import,

      it would be smart enough to go ahead and do so... apparently not.

      And now Im not sure what angle to attack this from.

       

      If anyone has any experience with this kind of thing, I would greatly appreciate the help.

       

      My Background: junior - intermediate php/xml/web developer.

      This is my first major FM project.

        • 1. Re: Import images into FM from an xml http data source
          stewieK
            

          stewieK wrote:

          Long story short I have mainly textual data stored on a server in a mysql data base and I want to import it into FM.

           

          So I pull the data from the DB and with PHP I create an FM friendly XML file,

          which is then pulled into FM via an HTTP import...

          Cool, easy... still with me?... good.

           

          The trick is I have a few images and pdf files that I need to import into the record at the same time as the rest of the data.

          They are stored in a directory on the server separate to the textual data, but the file reference (URI) is in the XML record I'm sending down.

           

          Now I would have thought that if I gave the container field, in FM, the file reference to the image I want it to download, during the import,

          it would be smart enough to go ahead and do so... Apparently not.

          And now Im not sure what angle to attack this from.

           

          If anyone has any experience with this kind of thing, I would greatly appreciate the help.

           

          My Background: junior - intermediate php/xml/web developer.

          This is my first major FM project.


          Cool, so I think I answered my own Question:

          Write a script that imports all the textual info (including the file ref) via HTTP first.

          Then have the container field do a second (file) import using the file ref from the first one.

          Done.

           

          Thanks


          • 2. Re: Import images into FM from an xml http data source
            FentonJones
              

            I don't quite know if you mean XML Import, as there is not really an HTTP Import. But, yes, once you have the file path, you can get the image. But I don't think you can "import" from a web URL. What you can do is download the image to a local file, could be into a temporary folder, then import the resulting file.

             

            This can be done fairly easily on a Mac, using the Perform AppleScript script step, running a curl command via the do shell script AppleScript command.

             

             

            set temp_folder to POSIX path of (path to temporary items from user domain)

            -- for me: "/Users/fej/Library/Caches/TemporaryItems/"

            do shell script "cd " & temp_folder & " && curl -fO http://fentonjones.com/images/Canna.jpg"

            -- will download the specified file to the temp folder, with its name

            -- the -f option causes an error if the file is not there, which you can capture via a FileMaker Set Error Capture ["On"]

            -- the -O (an "O", not a zero) says to just use the file's name

             

            do shell script "open " & temp_folder

            -- remove comments in front of above line, if you want to see the file 

             

             

            You would need to tell the AppleScript what the http path of the image was. You'd do this by via either building the below with an calculation, or you could pass the path to the AppleScript, from a field on the layout, or specified via its table occurrence (table in AppleScript) or layout name. Example:

             

            Field is on the layout:

             

            set image_url to cell "image_url" of current record 

             

            layout reference, file need not be on current layout:

             

            set image_url to cell "image_url" of current record of layout "AS_Paths" 

             

            The shell command would then look more like:

             

            do shell script "cd " & temp_folder & " && curl -fO " & image_url 

            • 3. Re: Import images into FM from an xml http data source
              stewieK
                

              Sorry, yes XML import from a HTTP source.

              Thanks for that

              • 4. Re: Import images into FM from an xml http data source
                clinke

                 


                stewieK wrote:

                Cool, so I think I answered my own Question:

                Write a script that imports all the textual info (including the file ref) via HTTP first.

                Then have the container field do a second (file) import using the file ref from the first one.

                Done.

                 

                Thanks


                 

                 

                 

                Would you mind sharing how exactly how you scripted it?


                • 5. Re: Import images into FM from an xml http data source
                  stewieK

                  Hey Clinke,

                  Honestly i can not remember what project this was for, but ill have a dig around and post somthing up if I can find it

                  :D