Topics
All
MacOS
(Only)
Windows
(Only)
Linux
(Only, Not)
iOS
(Only, Not)
Components
Crossplatform Mac & Win
Server
Client
Old
Deprecated
Guides
Examples
Videos
New in version:
12.2
12.3
12.4
12.5
13.0
13.1
13.2
13.3
13.4
13.5
Statistic
FMM
Blog
Reads a file with the given path.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
Container | 6.4 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameter | Description | Example | Flags |
---|---|---|---|
FilePath | The native file path. Something like "/Users/cs/desktop/test.txt" on Mac and "C:\Programs\Data\test.txt" on Windows. Files without path end in the root directory on Mac. | "test.txt" | |
mode | If missing or "auto", the plugin will try to detect type by file name extension. If filter is "container", the result is returned as a container with a FILE stream inside. The type can be specific here like PDF, JPEG, TIFF, GIF, BMP or PSD to return as image container. Or "compressed" to return a compressed container. |
"Auto" | Optional |
filename | If result is container, this defines the file name to use. | "test.txt" | Optional |
Returns container value or error.
Read image file:
Set Variable [ $fileContent; Value: MBS( "Container.ReadFile"; "/Users/cs/Pictures/test.jpg"; "auto")]
Read image file with error checking:
# get native path
Set Variable [ $path ; Value: "/Users/cs/Pictures/mond.jpg" ]
#
# read file
Set Variable [ $content ; Value: MBS( "Container.ReadFile"; $path) ]
#
# check for error
If [ MBS("IsError") = 0 ]
Set Field [ Contacts::Photo Container ; $content ]
Else
Show Custom Dialog [ "Failed to read file." ; $content ]
End If
Save as PDF and import it to a field:
# go to layout and record before
# build a path for FileMaker
Set Variable [ $name ; Value: "test.pdf" ]
Set Variable [ $path ; Value: Get(DocumentsPath) & $name ]
Set Variable [ $NativePath ; Value: MBS( "Path.FileMakerPathToNativePath"; $path ) ]
#
# Let FileMaker save records
Save Records as PDF [ With dialog: Off ; “$path” ; Records being browsed ; Create folders: Off ]
Set Variable [ $error ; Value: Get(LastError) ]
If [ $error = 0 ]
# Read result PDF
Set Variable [ $PDF ; Value: MBS( "Container.ReadFile"; $NativePath) ]
If [ MBS("ISError") = 0 ]
# Put in container
Set Field [ Contacts::PDF File ; $PDF ]
Else
Show Custom Dialog [ "Failed to read PDF document" ; $PDF ]
End If
Else
Show Custom Dialog [ "Failed to create PDF document" ; Get(LastExternalErrorDetail) ]
End If
Import file on Server on Windows:
MBS( "Container.ReadFile"; "C:\Programs\FileMaker Server\Data\Documents\test.pdf")
Import all files in a folder:
# list files in a folder
Set Variable [ $r ; Value: MBS("Files.List"; $FolderPath) ]
# loop over the files
Set Variable [ $count ; Value: ValueCount ( $r ) ]
Set Variable [ $index ; Value: 0 ]
If [ $count>0 ]
Loop
# build path
Set Variable [$fileName; GetValue ( $r ; $index+1 )]
Set Variable [$filePath; Value: MBS( "Path.AddPathComponent"; $FolderPath; $fileName )]
Set Variable [$fileData; Value: MBS("Container.ReadFile"; $filePath)]
# create record for new file
New Record/Request
Set Field [MyData::Container; $fileData ]
Set Field [MyData::Name; $fileName ]
Commit Records/Requests [ With dialog: Off ]
Set Variable [ $index ; Value: $index + 1 ]
Exit Loop If [ $index = $count ]
End Loop
End If
This function is free to use.
Created 6th September 2016, last changed 2nd August 2023