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

    Insert file into container field using jdbc

    pm

      Title

      Insert file into container field using jdbc

      Post

           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

      http://forums.filemaker.com/posts/e099bb62f8?commentId=241893#241893

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

               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
            pm

                 Mikhail,

                 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() );

                 Thanks!

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

                   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:

                   \x00\x00\x00\x01\x04<36?\x00\x04.?).

                   (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.