7 Replies Latest reply on Apr 29, 2013 10:54 AM by pm

    Saving an image to a container field (and it's name) using JDBC

    MorkAfur

      Title

      Saving an image to a container field (and it's name) using JDBC

      Post

      I have code that, currently, writes the image data from a JPEG on the desktop to a container field in FMP 12. That part's fine.

      What I can't figure out yet how to do is to also set the image NAME.

      When I extract the image data from the database, I use two SQL statements defined in the excellent FMP JDBC programming manual: 1 for the image name, the other for the image data. When I tried to reverse this to write the image data back to the container field with the file name too, it doesn't work. What happens is that which ever is the second statement overwrites whatever the first statement did.

      For those looking to do this too, this link gets you fairly close: http://www.skeletonkey.com/FileMaker_Container_Fields_JDBC

      I would really appreciate any ideas or examples on how best to save both the image data (which I can do now) and also, at the same time, set the image name in the container field using JDBC.

      Thanks in advance,
      -m

        • 1. Re: Saving an image to a container field (and it's name) using JDBC
          philmodjunk

          The image name should be stored in a text field on the same record as the container field, it should not be stored in the container field.

          • 2. Re: Saving an image to a container field (and it's name) using JDBC
            MorkAfur

            That might be the best solution, but ....

            If I have an image in a container field already, and export it, I is saved with the image's file name. Therefore, I'm guessing there must be someway to reverse that process and get the iamge data with the image.

            Do you know for a fact that it isn't reversible? That is, you can extract both the image AND the name from the container field (I am doing this now), but NOT save both the image AND the image name back TO the container field.

            Look forward to your reply.

            Thanks.

            • 3. Re: Saving an image to a container field (and it's name) using JDBC
              MorkAfur

              Never mind my previous post, Phil.

              I like your idea better. Getting the image names is tough enough as it is for the user. Having a separate field for the file name, if the client even needs that information, is a better way to go.

              Sometimes the simplest suggestion is the best. :)

              Thanks again!

              - m

              • 4. Re: Saving an image to a container field (and it's name) using JDBC
                philmodjunk

                It is possible to extract a filename from a container field, but you don't use a second set field to add the file name to the container field, the insert process has already done that for you.

                This calculation will extract a filename from a container field:

                Let ( L = Length ( GetAsText ( YourContainerField ) ) ;
                       Right ( YourContainerField ; L - Position ( YourContainerField ; "/" ; L ; - 1 ) )
                     )

                This should work for all insert options as they all end with the filename as far as I can recall.

                • 5. Re: Saving an image to a container field (and it's name) using JDBC
                  MorkAfur

                  That's nice. I'll keep that code handy.

                  I guess I wasn't clear initially, but I'm doing this all in Java using JDBC to connect to the FMP database.

                  Using JDBC, and just INSERT statements, I don't see how to update the container field with the file name.

                  If I drag an image with a file name into a container field and then Export it (manually using the FMP interface), the file name of the file is given as the default. And, using JDBC and two SQL Statements, programatically, I can extract both the file name (if it exists) and the file data.

                  However, going back the other way, using JDBC and INSERT and UPDATE statements, I'm not sure how to add the file name later. If I insert an image file using an INSERT statement, then go into FMP and say Export, the default option is "Untitled", which leads me to believe that the file name didn't get saved, right?

                  So I think having a separate field for the file name is a quick and simple (elegant) solution for at least programmatic handling of images.

                  Thanks,

                  • 6. Re: Saving an image to a container field (and it's name) using JDBC
                    philmodjunk

                    Using JDBC, and just INSERT statements, I don't see how to update the container field with the file name.

                    And you wouldn't do that as you don't need to, the Insert statements should do that for you when you insert the image.

                    My point with the calculation that I just suggested as you don't actually need the separate text field as you can use a calculation to extract the filename from the container field after the image is inserted.

                    • 7. Re: Saving an image to a container field (and it's name) using JDBC
                      pm

                           Has anyone found a solution to this?  By following this post:

                      http://www.skeletonkey.com/FileMaker_Container_Fields_JDBC i end up with a untitled.jpg. 

                           Any help will be appreciated.thanks.