Files.ReadFile
--------------

Reads a file with the given path.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Files](component_Files.md) | [3.5](newinversion35.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "Files.ReadFile"; FilePath { ; Mode; FileName } ) 

**MBS**( **"Files.ReadFile";** /\* Reads a file with the given path. \*/  
**$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.e.g. "test.txt" \*/   
**$Mode**; /\* Optional; auto: to auto detect the type of container based on the file name.  
base64: pass base64 to encode data first to base64 encoding.   
Base64URL: Base64URL encoding.  
Hex: Can be Hex to encode to hex encoding.   
container: the result is returned as a container with a FILE stream inside.  
jpg: Return as JPEG container.  
png: Return as PNG container.  
tif: Return as TIFF container.  
gif: Return as GIF container.  
bmp: Return as BMP container.  
psd: Return as PSD container.  
pdf: Return as PDF container. This may calculate a preview image.  
  
Default is return content as text if you pass "" or ommit the parameter.e.g. "" \*/   
**$FileName**) /\* Optional; If mode is container, this defines the file name to use.e.g. "test.txt" \*/ 

### 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 | auto: to auto detect the type of container based on the file name.   base64: pass base64 to encode data first to base64 encoding.    Base64URL: Base64URL encoding.   Hex: Can be Hex to encode to hex encoding.    container: the result is returned as a container with a FILE stream inside.   jpg: Return as JPEG container.   png: Return as PNG container.   tif: Return as TIFF container.   gif: Return as GIF container.   bmp: Return as BMP container.   psd: Return as PSD container.   pdf: Return as PDF container. This may calculate a preview image.      Default is return content as text if you pass "" or ommit the parameter. | "" | Optional |
| FileName | If mode 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 text with native encoding. This may truncate the string at the first null byte.  
You can optionally define a mode like base64 or Hex to read any bytes including null bytes.   
See also [Text.ReadTextFile](TextReadTextFile.md) for reading text files with specific encoding.  
  
Reading files over 1 GB is not supported. Use [Container.ReadFile](ContainerReadFile.md) for bigger files.  
Added new modes with version 5.3: auto, compressed, pdf, png, jpg, tif, gif, bmp or psd.  
  
For reading simple text files, please use [Text.ReadTextFile](TextReadTextFile.md).  
See also specialized functions [Files.ReadJPEG](FilesReadJPEG.md), [Files.ReadPDF](FilesReadPDF.md), [Files.ReadPNG](FilesReadPNG.md), [Text.ReadTextFile](TextReadTextFile.md) and [RichText.ReadFile](RichTextReadFile.md).  
  
For PDF content: If you have a DynaPDF Pro license and [DynaPDF](component_DynaPDF.md) functions initialized, this function can add previews for the PDF file on Windows and Linux. For MacOS, we make them with PDFKit.  
  
This function requires a native path. Use [Path.FileMakerPathToNativePath](PathFileMakerPathToNativePath.md) 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](component_FileDialog.md) functions.  
For Server be aware that server has limited permissions and may not be able to access all files on a computer.  
### Examples

Read file with some data:

 MBS ("Files.ReadFile"; $Path )  
Read file with some data and encode base64:

 MBS ("Files.ReadFile"; "/Users/cs/Desktop/test.txt"; "base64")  
Read as compressed container:

 Set Field \[Container Compression::SomeContainer ; MBS ("Files.ReadFile"; "/Users/cs/Desktop/test.jpg"; "compressed"; "test.jpg")\]  
Read file on Server:

 MBS ( "Files.ReadFile"; "C:\\Programs\\FileMaker Server\\Data\\Documents\\test.pdf")  
### See also

- [Files.CopyFile](FilesCopyFile.md)
- [Files.MoveFile](FilesMoveFile.md)
- [Files.ReadJPEG](FilesReadJPEG.md)
- [Files.ReadPDF](FilesReadPDF.md)
- [Files.RevealFile](FilesRevealFile.md)
- [ImageCapture.Download](ImageCaptureDownload.md)
- [RichText.ReadContainer](RichTextReadContainer.md)
- [RichText.ReadFile](RichTextReadFile.md)
- [RichText.WritePDF](RichTextWritePDF.md)
- [Text.ReadTextFile](TextReadTextFile.md)

### Release notes

- **Version 10.3**
    - Added Base64URL as output option for [RSA.Sign](https://www.mbsplugins.eu/RSASign.shtml), [CURL.ReceiveData](https://www.mbsplugins.eu/CURLReceiveData.shtml), [Files.ReadFile](https://www.mbsplugins.eu/FilesReadFile.shtml), [Hash.DigestFile](https://www.mbsplugins.eu/HashDigestFile.shtml), [Hash.Digest](https://www.mbsplugins.eu/HashDigest.shtml), [Encryption.Cipher](https://www.mbsplugins.eu/EncryptionCipher.shtml) and for other functions as text encoding parameter.

### Example Databases

- [CURL/WebServices/WeatherBit.io test](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/WebServices/WeatherBit.io%20test.shtml#4ScriptAnchor_)
- [Drag and Drop/DragTest Popover](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Drag%20and%20Drop/DragTest%20Popover.shtml#3ScriptAnchor_)
- [Drag and Drop/DragTest](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Drag%20and%20Drop/DragTest.shtml#3ScriptAnchor_)
- [Drag and Drop/for Mac/DragTest multiple picture files](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Drag%20and%20Drop/for%20Mac/DragTest%20multiple%20picture%20files.shtml#3ScriptAnchor_)
- [Mac and iOS/Machine Learning/Core ML Photos](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Mac%20and%20iOS/Machine%20Learning/Core%20ML%20Photos.shtml#1ScriptAnchor_)
- [Mac and iOS/PDFKit/PDF Merge Shrink Tool](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Mac%20and%20iOS/PDFKit/PDF%20Merge%20Shrink%20Tool.shtml#3ScriptAnchor_)
- [Mac only/ImageCapture/Camera Import](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Mac%20only/ImageCapture/Camera%20Import.shtml#6ScriptAnchor_)

### Blog Entries

- [MBS FileMaker Advent calendar - Door 20 - Scan and Recognize](https://www.mbsplugins.de/archive/2024-12-20/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Advent calendar - Door 3 - Drag &amp; Drop](https://www.mbsplugins.de/archive/2024-12-03/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [MBS Plugin Advent calendar: 12 - Files](https://www.mbsplugins.de/archive/2023-12-12/MBS_Plugin_Advent_calendar_12_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 10.3pr1](https://www.mbsplugins.de/archive/2020-06-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [FileMaker 18 File Script Steps vs. BinaryFile functions](https://www.mbsplugins.de/archive/2019-06-03/FileMaker_18_File_Script_Steps/monkeybreadsoftware_blog_filemaker)
- [Adding Drag and Drop receiver to a layout](https://www.mbsplugins.de/archive/2018-10-08/Adding_Drag_and_Drop_receiver_/monkeybreadsoftware_blog_filemaker)
- [\[ANN\] MBS FileMaker Plugin 5.3 for OS X/Windows](https://www.mbsplugins.de/archive/2015-10-01/[ANN]_MBS_FileMaker_Plugin_53_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 5.3pr4](https://www.mbsplugins.de/archive/2015-09-22/MBS_FileMaker_Plugin_version_5/monkeybreadsoftware_blog_filemaker)
- [Compressed Containers](https://www.mbsplugins.de/archive/2015-09-16/Compressed_Containers/monkeybreadsoftware_blog_filemaker)
- [MBS Filemaker Plugin, version 4.4pr6](https://www.mbsplugins.de/archive/2014-10-20/MBS_Filemaker_Plugin_version_4/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 4/2025, Seite 31 bis 32](https://filemaker-magazin.de/neuigkeit/4297-Appetithappen-FMM_202504)

This function is free to use.

Created 18th August 2014 , last changed 25th October 2024

  
[Files.ReadAndWriteFile](FilesReadAndWriteFile.md) - [Files.ReadJPEG](FilesReadJPEG.md)

[HTML Version](FilesReadFile.shtml)