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:
9.3
9.4
9.5
10.0
10.1
10.2
10.3
10.4
10.5
10.6
Statistic
FMM
Blog
Container.ReadFile
Reads a file with the given path.
| Component | Version | macOS | Windows | Linux | Server | FileMaker iOS SDK |
| Container | 6.4 | Yes | Yes | Yes | Yes | Yes |
Parameters
| 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 |
Result
Returns container value or error.
Description
Reads a file with the given path.Reads the data in the file and returns as container.
See also Text.ReadTextFile for reading text files with specific encoding.
For reading simple text files, please use Text.ReadTextFile.
See also Files.ReadFile, Files.ReadJPEG, Files.ReadPDF, Files.ReadPNG, Text.ReadTextFile and RichText.ReadFile.
This function is optimized for FM 14 and newer to stream file content when using auto mode. This allows to import up to 4 GB of data in small chunks.
This function requires a native path. Use Path.FileMakerPathToNativePath to convert a FileMaker path to a native path if required. If you like to have the user choose the path, you can use FileDialog functions.
For Server be aware that server has limited permissions and may not be able to access all files on a computer.
Examples
Read image file:
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
See also
- Container.ReadArchive
- Container.WriteFile
- IKScannerDevicePanel.SetTrigger
- ImageCapture.ImagePaths
- ImageCapture.SetParameter
- IsError
- RichText.ReadFile
- Text.ReadTextFile
- WIA.Image
- WIA.ImageCount
Example Databases
- DynaPDF/PDF Library
- iOS/DocumentPicker iOS
- Mac and iOS/Contacts/Contacts
- Mac only/ImageCapture/ImageCapture Dialogs
- Mac only/ImageCapture/ImageCapture
- SQL in FileMaker/ImageGallery
- Utility functions/Trigger Script on Plugin Error
- Win Only/WIA Scan
Blog Entries
- Save PDF to container in FileMaker
- Read HEIC or HEIF image files in FileMaker
- FileMaker 18 File Script Steps vs. BinaryFile functions
- Comparing Base Elements Plugin to MBS FileMaker Plugin
- ImageCapture functions for Mac OS X
- MBS FileMaker Plugin, version 6.4pr6
FileMaker Magazin
Created 6th September 2016, last changed 27th November 2020
Container.ReadArchive - Container.ReadImage
Feedback: Report problem or ask question.
Links
MBS Xojo Plugins