Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

Container.Export

Writes selected data content from a container to a file path.

Component Version macOS Windows Linux Server iOS SDK
Container 1.6 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "Container.Export"; Container; Index or Type; FilePath )   More

Parameters

Parameter Description Example
Container The container where the data is stored.
Index or Type Specify what part of the container to export.
e.g. "JPEG", "PDF ", "GIFf" or "PICT") or the index.
"JPEG"
FilePath Absolute path to store file.

Result

Returns "OK" on success or error message.

Description

Writes selected data content from a container to a file path.
Warning: Most people trying this function, really need the Container.WriteFile function!

For example you can write out from a TIFF image stored in the database the TIFF data itself or the preview JPEG.
Please note that types are always 4 characters long, "PDF " has a space on the end.
Some of the allowed types include "TIFF", "PDF ", "PNGf", "GIFf", "BMPf", "EPS ", "PICT", "M4V ", "WAV ", "M4A ", "MOV ", "AVI ", "AU ", "MP3 ", "MPEG", "MPG4", "AIFF", "8BPS", "FILE", "MAIN", "JPEG" and maybe some more.
Use functions like Container.GetTypes or Container.GetType to check what is inside a container.

To convert image formats, please review GraphicsMagick functions like GMImage.NewFromContainer and GMImage.WriteToPNGContainer.
To convert PDF to PNG, check functions like PDFKit.GetPDFPageImage, DynaPDF.GeneratePreview or DynaPDF.RenderPage.

This function is only for internal containers. Please use Container.WriteFile for all containers.
You can use Files.ReadFile to read a file into a container field or variable.

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

Export JPEG file:

MBS("Container.Export"; Files::data; "JPEG"; GetAsText(Files::data)+".jpg")

Export all streams in container to individual files:

Set Variable [$container; Value:Test::Image]
#where to save
Set Variable [$DesktopFolder; Value:MBS("Folders.UserDesktop")]
#loop over streams in container
Set Variable [$count; Value:MBS( "Container.GetCount"; $container )]
Set Variable [$index; Value:0]
Loop
    #query the type of stream with given index
    Set Variable [$type; Value:MBS( "Container.GetType"; $container; $index )]
    #write it to a file
    Set Variable [$path; Value:$DesktopFolder & "/" & $type]
    Set Variable [$r; Value:MBS( "Container.Export"; $container; $index; $path )]
    #next
    Set Variable [$index; Value:$index + 1]
    Exit Loop If [$count = $index]
End Loop

Export a container to desktop:

# get path stored in the container field
Set Variable [ $ContainerPath ; Value: GetAsText ( Contacts::Photo Container ) ]
# get the file name portion
Set Variable [ $ContainerName ; Value: MBS( "Path.LastPathComponent"; $ContainerPath ) ]
# take a folder on the computer, e.g. desktop
Set Variable [ $DesktopFolder ; Value: MBS( "Folders.UserDesktop" ) ]
# build path with file name on that folder
Set Variable [ $FilePath ; Value: MBS( "Path.AddPathComponent"; $DesktopFolder; $ContainerName ) ]
# and export the content of container to that path
Set Variable [ $r ; Value: MBS( "Container.WriteFile"; Contacts::Photo Container; $FilePath ) ]

See also

Example Databases

Blog Entries

This function checks for a license.

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


Container.Deserialize - Container.ExtractStream