1 2 3 Previous Next 31 Replies Latest reply on Jan 7, 2015 2:11 PM by pjreagan

    Problem using Base64Decode to rename a container file

    wfgclapp

      Hello,

      I am using the following calculation with SetField in a script to rename an externally stored container file (jpg image).

      Base64Decode ( Base64Encode (Employee::Emp_Pic) ; Employee::Employee_ID&".jpg" )

      The image is of an employee, taken in FMGo and the calculation will rename the file to be employeenumber.jpg

       

      My problem arises if I am replacing a particular employee image with a new one. When this happens, the file is renamed but with the new addition of '_x' after the employee number, with x starting as 1 and incrementing with each new version of the picture I take.

      Example for employee 1005:

      1. Original image: my calculation renames to 1005.jpg  (no problem here)

      2. First re-take: my calculation renames to 1005_1.jpg (bad)

       

      Any thoughts on how to get the increment to stop? I need the filename to remain 1005.jpg, for example.

       

      THanks!

        • 1. Re: Problem using Base64Decode to rename a container file
          pjreagan

          It's unclear from this description when the renaming takes place.  Is it in a triggered script when the container is modified by a user taking a picture?  Or is this script invoked as a maintenance process, long after the picture was taken?  Either way: Have you already tried having the script clear the container field before the replacement file is set?  (Maybe the script could first set the original picture to a temporary container field so a revert is possible.)

          • 2. Re: Problem using Base64Decode to rename a container file
            schamblee

            Base64Decode is not intend to be use to rename the file.    The command allow you to give a file a name and the name you are giving already exist so Filemaker is adding a underscore and number to the filename, so it does not overwrite a file.  I would suggest using a plugin or apple script (Mac), or a batch file(PC) to handle the file renaming.

            • 3. Re: Problem using Base64Decode to rename a container file
              gcatnine

              I tested it with FM 13v4 and I was unable to riproduce your case. it worked fine, as you expected.

              May be you just store a reference for the file, and FM is not allow to replace it.

              If this is the case, change the memorization to store the full content.

              • 4. Re: Problem using Base64Decode to rename a container file
                gcatnine

                Sorry, but this is just a working trick when you like to change the name of a file stored in a container.

                • 5. Re: Problem using Base64Decode to rename a container file
                  Benjamin Fehr

                  works with my solution √

                  I'ld recommend to perform most current FMP update and see if the problem consists.

                   

                  If any "_1" (counting up) is added to the filename, either Mac filesystem OR FMP "seem" to believe that a file with same name already exists and adds a number in favour to protect the existing file.

                  • 6. Re: Problem using Base64Decode to rename a container file
                    schamblee

                    If it was a working trick then you wouldn't be asking a question about having a problem.    It's not intended to work that way, the command was not created to rename files.  I'm guessing it is not really renaming it is copying to a new file with the filename you are giving it, so you can't delete until it is finished, so filemaker has no choice but to add an underscore and number.  You may have to rename from employee id to temp.jpg and then run the command again to rename from temp.jpg to employeeid.jpg. 

                    • 7. Re: Problem using Base64Decode to rename a container file
                      wimdecorte

                      schamblee wrote:

                       

                      If it was a working trick then you wouldn't be asking a question about having a problem.    It's not intended to work that way

                       

                      +1

                       

                      If it is a "trick" then it is not part of the core functionality and it can be changed by the underlying code at any time.  Given that I would not rely on it as part of a core functionality of my solution.

                      • 8. Re: Problem using Base64Decode to rename a container file
                        schamblee

                        I agree that is why I suggest other options in my first post.   I would bet that the other options would be faster, because as I stated I  believe the Base64Decode command is copying instead of renaming, which would have to be done twice, if you add up the time to copy a 4mb file twice on a network solution, you are creating a bottleneck. 

                        • 9. Re: Problem using Base64Decode to rename a container file
                          wfgclapp

                          interesting. how do you change to store full content?

                          • 10. Re: Problem using Base64Decode to rename a container file
                            wfgclapp

                            ive been playing around with this option and have a question. how would one perform a 'revert'?

                             

                            for instance, i created a tmp container field and tried to move my image file from it to my 'perm' container field using the 'ReplaceFieldContents' function but that doesnt seem to work.

                            • 11. Re: Problem using Base64Decode to rename a container file
                              wfgclapp

                              Sorry. The renaming is within a script that is run by the user at the time of taking the picture.

                              1. InsertFromDevice

                              2. Rename with Base64Decode

                              3. Commit Records

                               

                              how would you clear the container? Do a SetField = ""?

                              • 12. Re: Problem using Base64Decode to rename a container file
                                pjreagan

                                Maybe try something like this:

                                1)  Add an OnObjectEnter triggered script that sets a secondary container field with the contents of the existing (primary) container field when the primary is entered.  (This secondary could be a global container field so that it is automatically cleared at the end of the user's session.)  Then, yes, clear the primary container field by setting it to = ""

                                2)  Add an OnObjectExit triggered script that checks the content of the primary container field.  If the IsEmpty function tells you that the primary field is empty, have the script set the primary field from the secondary field. 

                                3)  Keep your existing renaming script (which is triggered by an OnObjectModify trigger?)

                                 

                                I just did this on a test file and it seems to work on FMP 13 and FM Go 13

                                 

                                As for whether this renaming trick should be used in the first place, I respect the voices of concern about using an undocumented feature in a production database.  But, in the history of FM, there's been many fun tricks like this.  I've used some in production settings.  My take is that you have to make a judgement call: Is no alternative technique available?  With the system you're building, how much control do you have over FM updates?  Can you test the next version before your users update?  Is the immediate benefit of using it worth the risk of possibly having to rebuild the mechanism later on?

                                 

                                I'm happy to have learned about this trick, and might use it.  Thanks!

                                 

                                PS: be careful of the Replace function!  It works on all records in the found set!

                                • 13. Re: Problem using Base64Decode to rename a container file
                                  gcatnine

                                  If you use a script to insert the image, in the “Insert File” there is a button to specify Storage Option and in there you have to select “Insert”. That force to insert the full content.

                                  Otherwise, in the window, where you select the file, do not check the option in the lower left corner “Store only a reference to the file”.

                                  In the field definition, you can choose in the “Storage” tab where to store the container: internally, externally, safe or open mode.

                                  • 14. Re: Problem using Base64Decode to rename a container file
                                    wimdecorte

                                    wfgclapp wrote:

                                     

                                    Sorry. The renaming is within a script that is run by the user at the time of taking the picture.

                                     

                                    1. InsertFromDevice

                                    2. Rename with Base64Decode

                                    3. Commit Records

                                     

                                     

                                    In this case, you could the insertFromDevice into a global container, use Export Field Contents to export the inserted file using the new file name you want, then do an Insert Picture script step to grab the exported file back and store it in the proper container.

                                    All native,, and should be just as fast.

                                    1 2 3 Previous Next