April 19, 201312 yr As you can't use the Export Field Contents step when running a script through FileMaker Server, I threw together the following ScriptMaster script. Any suggestions or improvements welcome. Write Container to File ( filePath ; containerField ) import org.apache.commons.io.*; InputStream input; FileOutputStream out; try{ input = fmpro.getContainerStream(containerField); } catch(e){ return false; } if ( input == null ) { return false; } try{ output= new FileOutputStream( filePath ); } catch(e){ return false; } IOUtils.copy (input, output ); //int read = 0; //byte[] bytes = new byte[1024]; //while ((read = input.read(bytes)) != -1) { // output.write(bytes, 0, read); //} return true;
April 23, 201312 yr Author Oh... you'll need Apache.org's Common-IO library for this to work. http://commons.apache.org/proper/commons-io/
February 18, 201411 yr Hi Jonathan, Thank you posting this. I think it's exactly what I'm looking for, but I'm having trouble implementing. The function returns 0, and the containers fail to "export". I'm trying to write two container fields to a server's temporary folder. The variable that defines the folder: $PATHfolder = /private/var/folders/g6/3h4y328x1q5gc59q4hr_4xjr0000gn/T/tempKMZ_9A1902/ The variables that define the file paths: $PATHxml = /private/var/folders/g6/3h4y328x1q5gc59q4hr_4xjr0000gn/T/tempKMZ_9A1902/sample.xml $PATHpng = /private/var/folders/g6/3h4y328x1q5gc59q4hr_4xjr0000gn/T/tempKMZ_9A1902/19-tag.png Does that look right? Or could it be an error in my ScriptMaster module? I pasted your code, downloaded Apache Commons IO, and added five jars: commons-io-2.4-javadoc.jar commons-io-2.4-sources.jar commons-io-2.4-test-sources.jar commons-io-2.4-tests.jar commons-io-2.4.jar Not sure how to attach a screenshot, but it would show five Commons-Io selected in the Jars tab of the "Edit Script" layout. Thanks again for the module. Any further help is greatly appreciated. =L= _____ Leo Di Croce Feb 19, 2014 - Found a solution here.
March 4, 201411 yr Author Hey there, 1. The only jar you should need is "Commons-Io-2.4.jar". You shouldn't need any of the other jars. 2. There are two input variables. containerField - is the NAME of the container field. It should NOT be the value of container field itself. filePath - is the POSIX file path destination for the file in the container field. Hope that helps, JP
March 8, 201411 yr Hi Jonathan Can you post a sample file. I'm having a hart time trying to make it work. Sorry, I'm new to Java and Groovy. Regards Ibrahim
March 8, 201411 yr Author Here's the sample file. The call to the function is: WriteContainertoFile( "/Users/Shared/" & WriteContainerField::ContainerName ; "WriteContainerField::ContainerField" ) Also attached is a screenshot of the script in ScriptMaster and the JAR config in ScriptMaster. Its a pretty simple script to implement. WriteContainerField.fmp12.zip
February 2, 201510 yr Jonathan simplified code... import org.apache.commons.io.* if ( !input ) { return false } try{ input = fmpro.getContainerStream(containerField) output= new FileOutputStream( filePath ) IOUtils.copy (input, output ) } catch(e){ return false } return true
February 3, 201510 yr Hmmmm. When I run this I get a PDF file that is not complete or damaged. See the two PDFs below. About Downloads (Original).pdf About Downloads (Writen from Container).pdf
February 13, 201510 yr Just tested it and am getting the same issue as you... It's stopping at about 299k Tried it with about 3 or 4 other methods, but still the same result, indicating choking on the input side... And then i tried it with other PDF files (of which I have many for test, up to 50MB) And it all works as expected. I suspect that source PDF is in some way not lovely on the inside... Opened it with Acrobat Pro, re-saved it. All lovely. It's the PDF not the code. My code however is bad.. try import org.apache.commons.io.IOUtils try{ input = fmpro.getContainerStream(containerField) if ( !input ) { return false } output= new FileOutputStream( filePath ) IOUtils.copy(input, output) //for files over 2GB //IOUtils.copyLarge(input, output) } catch(e){ return false //return e } return true
February 14, 201510 yr Thank you so much. Can I ask about the large file option…I am a geneticist and have VERY large files sometimes. Is there some "cost" to implementing the Large file option all the time? Also, I have an issue with the java code reading a file into a container with large files…is there a similar solution for that? And also reading the content of a large file! Sorry to bother you guys but I'm a scientist not great programmer and these 3 things will make my life complete!!
February 14, 201510 yr add another parameter which indicates if the size is large.. for the other issues you might need to be using Buffered Stream methods if the files are large. posting code will help us to help you here.. import org.apache.commons.io.IOUtils try{ input = fmpro.getContainerStream(containerField) if ( !input ) { return false } //end if output= new FileOutputStream( filePath ) if (sizeParam){ //for files over 2GB IOUtils.copyLarge(input, output) } else { IOUtils.copy(input, output) } //end if } catch(e){ //turn on to see what errors are //return e return false } //end try return true
February 19, 201510 yr It's the standard "Read File Contents" module in Scriptmaster: if( pathToFile == null ) throw new Exception("You must supply a pathToFile parameter"); return new InputStreamReader( new FileInputStream( pathToFile ), "utf-8" ); And the standard "Get File As Container" module: File f = new File( pathToFile ); fileExists = f.exists(); return f; I have run out of memory with both I believe with large files
February 19, 201510 yr Also, your code from Posted 13 February 2015 - 03:03 PM works but your latest one doesn't. I guess you didn't finish it with the size parameter part?
July 8, 201510 yr Newbies Have you try with Mail-it ? Emai_ExportFile( fileObject; filePath {; saveMode; protectFile } ) /*Exports file object from container field to disk [i.e. an attachment that hasbeen retrieved from a message and stored in FileMaker]fileObject - File object to be exportedfilePath - Path [including file name and extension] to which the file willbe saved. If path does not include file name the default file namefrom object will be used.saveMode - "strict" [default], "rename" or "overwrite"protectFile - Used to write-protect the exported [temp] file if it should onlybe used for viewing purposes by the user. "modify" [default] doesnot write-protect the file. "read-only" protects it from modification.saveMode="strict" this function fails if there is an existing file.If saveMode="rename" plug-in adds a counter to the file name ifthere is a conflict with an existing file. If saveMode="overwrite"plug-in tries to overwrite existing file with the same name [if any]. */
February 22, 20178 yr Newbies The free BaseElements plug-in has a similar function: BE_ExportFieldContents ( field ; outputPath ) Exports the contents of the container field to disk at the outputPath specified. Container fields should be inserted via "Insert File". This provides a similar functionality to the Export Field Contents script step, but is also available via FileMaker Server.
March 28, 20178 yr I am playing around with this, but found that it is not compatible with the Get(DocumentsPath) or Get (TemporaryPath) commands in Filemaker. Anyone have any luck with that?
March 29, 20178 yr I would guess that BE expects OS paths, not FM paths. https://www.briandunning.com/cf/902
March 29, 20178 yr https://baseelementsplugin.zendesk.com/hc/en-us/articles/205350417-Notes-about-File-Paths <<The paths used by the plugin are Operating System paths, not FileMaker paths.......>> and same is true for ScriptMaster functions.
August 17, 20178 yr Here's another ScriptMaster module which doesn't require Apache IOUtils and supports FileMaker-style paths. It uses some internal ScriptMaster utilities instead, I'll add it to the ScriptMaster list of modules. Returns number of bytes transferred. The 4096 is the buffer size. Parameters: containerName path Script: import com.prosc.io.IOUtils; import com.prosc.fmkit.PluginUtils; inputStream = fmpro.getContainerStream(containerName) if (inputStream == null) throw new IOException(containerName + " is empty"); try { File f = PluginUtils.fileForFMPath(path); FileOutputStream out = new FileOutputStream(f); IOUtils.writeInputToOutput(inputStream, out, 4096); } finally { out.close(); inputStream.close(); }
September 4, 20178 yr Hi shmert, On 17. August 2017 at 8:25 PM, shmert said: Here's another ScriptMaster module which doesn't require Apache IOUtils and supports FileMaker-style paths. It uses some internal ScriptMaster utilities instead, I'll add it to the ScriptMaster list of modules. Returns number of bytes transferred. The 4096 is the buffer size. can you explain me, which extensions or java files I have to install and where to put them? If I try your script, it returns just "error". Regards, Thorsten
Create an account or sign in to comment