Colleen Posted July 30, 2010 Posted July 30, 2010 I'm attempting to convert an image stored in a container field to Base64 encoded text. I've tried using csm_base64_Encode with the container field as the input; however, it appears to me that rather than passing the image in the container I'm simply passing the text result (ie: image name) How do I pass the image itself? Many thanks!! Colleen
Jesse Barnum Posted July 30, 2010 Posted July 30, 2010 ScriptMaster only supports text parameters. However, you can pass in the name of the container field and then use the fmpro.getContainerStream() and fmpro.getContainerFileName() methods to grab the container data for the named field. You can see an example of this in the 'Zip File' module, which can zip a container field. Once you have the input stream, you can call the getBytes() method on it to get a byte array, which can then be Base64 Encoded. The final result will look like this: return new sun.misc.BASE64Encoder().encode( fmpro.getContainerStream( fieldName ).getBytes() ); This takes one input parameter, 'fieldName', which should contain the name of the container field. It will grab the data from the field in the current record with that name.
Colleen Posted July 30, 2010 Author Posted July 30, 2010 Jesse- Thank you for pointing me in the right direction! I tried testing this in the ScriptMater file; adding a container field & contents for the test and it worked (ie: I got a long string of text in the text result field.) I then registered the function and attempted to use that function in another file (it appears in the External functions list). However the new function returns an error and SMLastError returns: com.prosc.fmkit.FmCalculationException: 102 FileMaker error 102 would indicate a missing field... however, that doesn't make any sense. What's my problem? -Colleen
Jesse Barnum Posted July 30, 2010 Posted July 30, 2010 The most likely thing is that the name of the field that you're passing into the function doesn't exactly match the name of the field in the current table in the current file. This would cause a 102 error. If you're sure that they match, send me an example file that reproduces the problem and I'll take a look.
Newbies ovvk Posted September 3, 2010 Newbies Posted September 3, 2010 Hi Jesse, Just bought your adv scriptmaster version. But i am suffering the same problem as Colleen did. Do you have a solution for this problem? thx in advance Cor de Bruin
Colleen Posted September 3, 2010 Author Posted September 3, 2010 The fix for me was to send the correct parameter to my function; I used: outputContainer( Counselors::Photo ) Which should have been (notice the quotes) outputContainer( "Counselors::Photo" ) The function is expecting the NAME of the field, not the VALUE of the field. -colleen
Newbies ovvk Posted September 3, 2010 Newbies Posted September 3, 2010 (edited) Thx Colleen, it worked a few seconds after your post! Edited September 3, 2010 by Guest
andries Posted September 6, 2010 Posted September 6, 2010 just to avoid hardcoding of fieldnames you better use: outputContainer( GetFieldName ( Counselors::Photo ) )
Jim Randell Posted November 9, 2010 Posted November 9, 2010 Greetings all, Very glad to have found this topic! I have a variation on this usage, but I have a slight hangup. I have an image database with more then 100,000 images, and I want to find duplicates. My goal was to create a string, unique to each image, but consistant amoung duplicate images. I created and registered a new function I call ImageCODE using your example: "return new sun.misc.BASE64Encoder().encode( fmpro.getContainerStream( fieldName ).getBytes() );" I created a calc field in my image db, where I pass the field name into this function. Based on limited testing, it seems to work only sometimes. Its hard to get a better handle on it then that, because the strings are so long, any methods of comparison run too slow. Before I start chopping it up into smaller samples, I attempted to use Hashcode. I pasted the resulting text from one record into the Hashcode example in the SM file (and clicked "Run Script"). In your SM File, this works as expected, returning a very short string. But it returns "error" when I use the function in a calc field in my table: " hashcode(ImageCODE) ". I also pasted the same string which worked in the SM example, into the calc field ( hashcode("pasted text string") ), but this also returned an error. I have tried many variations (nested, separate fields, stored, unstored, Lets which evaluate, etc) and the function SMlastError returns Null. Any pointers would be greatly appreciated. Thanks, -JR
Recommended Posts
This topic is 5139 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now