Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Guides   Examples
New in version: 7.2   7.3   7.4   7.5   8.0   8.1   8.2   8.3   8.4   8.5    Statistic  

CURL.GetResultAsContainer

Returns the result of the transaction as container value with auto detection of type.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
CURL 5.2 Yes Yes Yes Yes Yes
MBS( "CURL.GetResultAsContainer"; curl { ; Filename; PluginDetect } )   More

Parameters

Parameter Description Example value
curl The CURL session handle. $curl
Filename Optional
The desired file name
test.jpg
PluginDetect Optional
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.

Result

Returns OK 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.

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; "http://monkeybreadsoftware.de/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.GetDebugAsText"; $curl)]
# cleanup
Set Variable [$r; Value:MBS("CURL.Cleanup"; $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.GetDebugAsText"; $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.Destroy";$ImageRef) ]
    End If
End If
Set Variable [ $r ; Value: MBS("CURL.Cleanup"; $curl) ]

Get file name for container from header:

Set Variable [ $name ; Value: "" ]
Set Variable [ $headers ; Value: MBS( "CURL.GetHeaderAsText"; $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

Example Databases

Created 15th June 2015, last changed 17th August 2018


CURL.GetResponseCode   -   CURL.GetResultAsData

Feedback: Report problem or ask question.




Links
MBS FileMaker Plugins