4 Replies Latest reply on Feb 22, 2013 9:12 AM by philmodjunk

    Can I see the size of the content of the container?

    marco96

      Title

      Can I see the size of the content of the container?

      Post

           Greetings everyone,

           I was wondering if there was a way to have a second field tell me the size of a containter field? As it is now I have to either check the size of a file before placing it in a container or extract the contents and check the size of the file. 

           It sure would be nice if I could just look at a field telling me the size fo the container.

           Thank you

           Marco

           FMP 10 on a mac

        • 1. Re: Can I see the size of the content of the container?
          davidanders
                    FMP 10 on Macintosh
                    Referenced or Embedded documents in container field?
                     
          Title:  Get file name and file size from a container field

          http://www.mightydata.com/blog/stop-embedding-documents-in-your-database/
          Stop Embedding Documents in Your Database!

                

          • 2. Re: Can I see the size of the content of the container?
            philmodjunk

                 One trick would be to use the filepath stored in a "by reference" container field to temporarily embed a copy of the file in a global container field. Then the Length function can be used to return the size of that file in bytes.

            • 3. Re: Can I see the size of the content of the container?
              marco96

                   Thank you for your help. It sounds a little complex. I will need to study this more and be careful not to let the containers grow the database too large.

                   Marco

              • 4. Re: Can I see the size of the content of the container?
                philmodjunk

                     What I describe shouldn't make a significant change to the size of your file.

                     What I describe would only add a single global container field that embeds only one file at a time as it has global storage specified. In a networked database, even that single embedded file will disappear from the global field when the file is closed.

                     The script would look like this:

                     Set Variable [$Path ; "file:" & Get ( TemporaryPath ) & "TempFile.jpg"]
                     export Field Contents [YourTable::Containerfield ; $Path ]
                     Insert File [Insert ; Globals::GlobalContainerField ; $Path ]
                     Set Field [YourTable::FileSize ; Length ( Globals::GlobalContainerField ) ]

                     Note "Insert" will not appear in your script step unless you are using FileMaker 12. The example script assumes that all fields are .jpg files. If the files are of varying file extensions, you can use this expression in place of "TempFile.jpg" to use the file's original file name--including the correct extension:

                     //This should work for all insertion and storage methods except "insert Object":
                     Let ( [T = GetAsText ( GetValue ( YourTable::containerField ; ValueCount ( YourTable::containerField ) ) ) ;
                                 L = Length ( T )];
                                 Right ( T ; L - Position ( T ; "/" ; L ; -1 ) )
                         )