3 Replies Latest reply on May 5, 2013 2:43 PM by MikhailEdoshin

    Insert file into container field using jdbc



      Insert file into container field using jdbc


           I'm trying to insert a file into a container field using jdbc. I did the same thing as here:http://www.skeletonkey.com/FileMaker_Container_Fields_JDBC. I end up with an untitled.jpg instead of the actual file name. Is there a way to set the filename based on what i passed in? The inputstream does not seem to keep the name around. Should some FM script be written to set the name of the file stored in the container? Is there an easy soluion to this?

           This seems to be an old question that has not been answered yet


        • 1. Re: Insert file into container field using jdbc

               The docs say there must be some PutAs() function that sets an individual stream of a container. A container in FM has multiple streams; it seems that by default it sets the 'FILE' stream with data. Try to also set the 'FNAM' stream with a string. I.e. as far as I understand it must be like:

               INSERT INTO table (PutAs( container, 'FILE' ), PutAs( container, 'FNAM' )) values (?, ?)

               which is then bound to parameters: file data stream and a string. Actually, I'm not sure if the latter must be a string (unicode) or a also a raw byte stream, but let's start with a string :)

          • 2. Re: Insert file into container field using jdbc


                 Thanks for the prompt reply.I cant seem to find any documentation with the 'FNAM' stream. I have tried  to do an update since the time I saw your post and have failed miserably.

                 This does not work:

                 String sql = "UPDATE TestTable SET (PutAs( Results, 'FILE' ) = ?, PutAs( Results, 'FNAM' ) = ?) WHERE \"SampleId\" ='1234'";

                 This works but gives me an untitled.jpg though I have tried setting the second parameter to a String and a InputStream but failed.

                  String sql = "UPDATE TestTable SET Results = PutAs(?, 'JPEG '), Results= PutAs(?,'FNAM')  WHERE \"SampleId\" ='1234'";

                 This is how I am converting my String to an inputStream.Is this the problem?

                 InputStream is = new ByteArrayInputStream( myString.getBytes() );


            • 3. Re: Insert file into container field using jdbc

                   Well, from what I see FileMaker uses VERY strange encoding on the FNAM stream. Could you try to set the 'FNAM' stream to the following string:


                   (The end dot is a part of the string.) This is how it looks in Python; the \xNN indicate individal byte codes, i.e. the first three bytes are zero, then one, then four and so on. Individual characters go as they are. The four characters at the end (BTW, the \x04 before seems to be the length of the string) are actually "test". You can see that "t" is mapped to a dot "." in both places. But I don't quite see why they're mapped this way.

                   If this works, I can produce a full encoding table.