Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
CURL.GetResultAsContainer
Returns the result of the transaction as container value with auto detection of type.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
CURL | 5.2 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
Parameter | Description | Example | Flags |
---|---|---|---|
curl | The CURL session handle. | $curl | |
Filename | The desired file name. Since 13.3 only used if download has no file name. |
test.jpg | Optional |
PluginDetect | If 1 the plugin will do the file type detection. If not provided or 0 and the FileMaker version is 13.0 or newer, the FileMaker engine will decide on the type. | Optional |
Result
Returns container value or error.
Description
Returns the result of the transaction as container value with auto detection of type.The plugin will detect the type of data based on the file extension.
If no filename is provided, the plugin uses the filename from the URL.
For PDF content: If you have a DynaPDF Pro license and DynaPDF functions initialized, this function can add previews for the PDF file on Windows and Linux. For MacOS, we make them with PDFKit.
For HEIF/HEIC images, please use Container.ReadImage to convert the image.
Examples
Load JPEG from URL to container:
# start new transfer
Set Variable [$curl; Value:MBS("CURL.New")]
# set URL
Set Variable [$r; Value:MBS("CURL.SetOptionURL"; $curl; "https://monkeybreadsoftware.com/filemaker/images/devcon2013.jpg")]
# run transfer
Set Variable [$ErrorCode; Value:MBS("CURL.Perform"; $curl)]
# get result as JPG and store in field:
Set Variable [$Result; Value:MBS( "CURL.GetResultAsContainer"; $curl)]
Set Field [test::MyContainerField; $Result]
# get debug messages:
Set Variable [$DebugMessages; Value:MBS( "CURL.GetDebugMessages"; $curl)]
# cleanup
Set Variable [$r; Value:MBS("CURL.Release"; $curl)]
Download picture and scale it down:
Set Variable [ $curl ; Value: MBS("CURL.New") ]
Set Variable [ $r ; Value: MBS("CURL.SetOptionURL"; $curl; MIX::URL) ]
Set Variable [ $r ; Value: MBS("CURL.SetOptionFollowLocation"; $curl; 1) ]
Set Variable [ $r ; Value: MBS("CURL.SetOptionMaxRedirs"; $curl; 3) ]
Set Variable [ $result ; Value: MBS("CURL.Perform"; $curl) ]
Set Variable [ $debug ; Value: MBS( "CURL.GetDebugMessages"; $curl) ]
If [ $result = "OK" ]
Set Variable [ $Image ; Value: MBS( "CURL.GetResultAsContainer"; $curl) ]
Set Variable [ $ImageRef ; Value: MBS("GMImage.NewFromContainer"; $image) ]
If [ MBS("IsError") = 0 ]
Set Variable [ $r ; Value: MBS("GMImage.Scale";$ImageRef; "256x256>") ]
Set Variable [ $ScaledImage ; Value: MBS("GMImage.WriteToJPEGContainer"; $ImageRef) ]
If [ MBS("IsError") = 0 ]
Set Field [ MIX::Image ; $ScaledImage ]
End If
Set Variable [ $r ; Value: MBS("GMImage.Release";$ImageRef) ]
End If
End If
Set Variable [ $r ; Value: MBS("CURL.Release"; $curl) ]
Get file name for container from header:
Set Variable [ $name ; Value: "" ]
Set Variable [ $headers ; Value: MBS( "CURL.GetHeaders”; $curl; "UTF-8") ]
Set Variable [ $headers ; Value: MBS( "List.MatchesPrefix"; $headers; "Content-Disposition: attachment; filename=") ]
If [ Length($headers) > 0 ]
Set Variable [ $name ; Value: Middle ( $headers ; 43 ; Length($headers) ) ]
End If
Set Field [ CURL Test::File ; MBS("CURL.GetResultAsContainer"; $curl; $name) ]
See also
- Container.ReadImage
- CURL.Perform
- CURL.Release
- CURL.SetOptionMaxRedirs
- GMImage.New
- GMImage.NewFromContainer
- GMImage.Release
- GMImage.Scale
- GMImage.WriteToJPEGContainer
- IsError
Release notes
- Version 13.4
- Fixed a possible crash in CURL.GetResultAsContainer function.
- Version 13.3
- Fixed CURL.GetResultAsContainer function to prefer the download name over the given fallback name.
- Version 8.5
- Fixed edge case for filename in CURL.GetResultAsContainer function.
- Version 7.2
- Changed CURL.GetResultAsContainer to use filename from Content-Disposition header.
- Fixed crash in CURL.GetResultAsContainer when detecting file extension from mime type.
Example Databases
- CURL/Amazon S3/Containers in S3
- CURL/CURL Custom Function
- CURL/CURL Download Picture
- CURL/CURL Download to Container
- CURL/Download Async
- WebViewer/WebViewer Images
Blog Entries
- MBS FileMaker Plugin, version 13.3pr1
- CURL Custom Function
- Translating Insert from URL options for CURL to MBS Plugin calls
- MBS FileMaker Plugin, version 8.5pr6
- MBS FileMaker Plugin, version 7.2pr1
- MBS FileMaker Plugin, version 6.3pr5
- MBS FileMaker Plugin, version 5.2pr4
This function checks for a license.
Created 15th June 2015, last changed 8th July 2023