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](component_CURL.md) | [5.2](newinversion52.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "CURL.GetResultAsContainer"; curl { ; FileName; PluginDetect } ) 

**MBS**( **"CURL.GetResultAsContainer";** /\* Returns the result of the transaction as container value with auto detection of type. \*/  
**$curl**; /\* The CURL session handle. \*/   
**$FileName**; /\* Optional; The desired file name.  
Since 13.3 only used if download has no file name.e.g. 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. \*/ 

### 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](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.  
  
For HEIF/HEIC images, please use [Container.ReadImage](ContainerReadImage.md) to convert the image.  
### Examples

Load JPEG from URL to container:

 # start new transfer   
Set Variable \[$curl ; Value:MBS ("[CURL.New](CURLNew.md)")\]  
\# set URL   
Set Variable \[$r ; Value:MBS ("[CURL.SetOptionURL](CURLSetOptionURL.md)"; $curl ; "https://monkeybreadsoftware.com/filemaker/images/devcon2013.jpg")\]  
\# run transfer   
Set Variable \[$ErrorCode ; Value:MBS ("[CURL.Perform](CURLPerform.md)"; $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](CURLGetDebugMessages.md)"; $curl )\]  
\# cleanup   
Set Variable \[$r ; Value:MBS ("[CURL.Release](CURLRelease.md)"; $curl )\]  
Download picture and scale it down:

 Set Variable \[ $curl ; Value: MBS ("[CURL.New](CURLNew.md)") \]   
Set Variable \[ $r ; Value: MBS ("[CURL.SetOptionURL](CURLSetOptionURL.md)"; $curl ; MIX::URL ) \]   
Set Variable \[ $r ; Value: MBS ("[CURL.SetOptionFollowLocation](CURLSetOptionFollowLocation.md)"; $curl ; 1) \]   
Set Variable \[ $r ; Value: MBS ("[CURL.SetOptionMaxRedirs](CURLSetOptionMaxRedirs.md)"; $curl ; 3) \]   
Set Variable \[ $result ; Value: MBS ("[CURL.Perform](CURLPerform.md)"; $curl ) \]   
Set Variable \[ $debug ; Value: MBS ( "[CURL.GetDebugMessages](CURLGetDebugMessages.md)"; $curl ) \]   
If \[ $result = "OK" \]   
 Set Variable \[ $Image ; Value: MBS ( "CURL.GetResultAsContainer"; $curl ) \]   
 Set Variable \[ $ImageRef ; Value: MBS ("[GMImage.NewFromContainer](GMImageNewFromContainer.md)"; $image ) \]   
 If \[ MBS ("IsError") = 0 \]   
 Set Variable \[ $r ; Value: MBS ("[GMImage.Scale](GMImageScale.md)";$ImageRef ; "256x256&gt;") \]   
 Set Variable \[ $ScaledImage ; Value: MBS ("[GMImage.WriteToJPEGContainer](GMImageWriteToJPEGContainer.md)"; $ImageRef ) \]   
 If \[ MBS ("IsError") = 0 \]   
 Set Field \[ MIX::Image ; $ScaledImage \]   
 End If  
 Set Variable \[ $r ; Value: MBS ("[GMImage.Release](GMImageRelease.md)";$ImageRef ) \]   
 End If  
End If  
Set Variable \[ $r ; Value: MBS ("[CURL.Release](CURLRelease.md)"; $curl ) \]  
Get file name for container from header:

 Set Variable \[ $name ; Value: "" \]   
Set Variable \[ $headers ; Value: MBS ( "[CURL.GetHeaders](CURLGetHeaders.md)”; $curl ; "UTF-8") \]   
Set Variable \[ $headers ; Value: MBS ( "[List.MatchesPrefix](ListMatchesPrefix.md)"; $headers ; "Content-Disposition: attachment; filename=") \]   
If \[ Length($headers ) &gt; 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](ContainerReadImage.md)
- [CURL.New](CURLNew.md)
- [CURL.Perform](CURLPerform.md)
- [CURL.Release](CURLRelease.md)
- [CURL.SetOptionFollowLocation](CURLSetOptionFollowLocation.md)
- [CURL.SetOptionMaxRedirs](CURLSetOptionMaxRedirs.md)
- [GMImage.Release](GMImageRelease.md)
- [GMImage.Scale](GMImageScale.md)
- [GMImage.WriteToJPEGContainer](GMImageWriteToJPEGContainer.md)
- [IsError](IsError.md)

### Release notes

- **Version 13.4**
    - Fixed a possible crash in [CURL.GetResultAsContainer](https://www.mbsplugins.eu/CURLGetResultAsContainer.shtml) function.
- **Version 13.3**
    - Fixed [CURL.GetResultAsContainer](https://www.mbsplugins.eu/CURLGetResultAsContainer.shtml) function to prefer the download name over the given fallback name.
- **Version 8.5**
    - Fixed edge case for filename in [CURL.GetResultAsContainer](http://www.mbsplugins.eu/CURLGetResultAsContainer.shtml) function.
- **Version 7.2**
    - Changed [CURL.GetResultAsContainer](http://www.mbsplugins.eu/CURLGetResultAsContainer.shtml) to use filename from Content-Disposition header.
    - Fixed crash in [CURL.GetResultAsContainer](http://www.mbsplugins.eu/CURLGetResultAsContainer.shtml) when detecting file extension from mime type.

### Example Databases

- [CURL/Amazon S3/Containers in S3](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Amazon%20S3/Containers%20in%20S3.shtml#4ScriptAnchor_)
- [CURL/CURL Custom Function](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/CURL%20Custom%20Function.shtml#3CustomFunctionAnchor_)
- [CURL/CURL Download Picture](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/CURL%20Download%20Picture.shtml#1ScriptAnchor_)
- [CURL/Download Async](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/Download%20Async.shtml#3ScriptAnchor_)
- [CURL/WebViewer Download Images with CURL](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/WebViewer%20Download%20Images%20with%20CURL.shtml#1ScriptAnchor_)
- [DynaPDF/Multi Column Output](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/Multi%20Column%20Output.shtml#5ScriptAnchor_)
- [WebViewer/WebViewer Images](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/WebViewer/WebViewer%20Images.shtml#2ScriptAnchor_)

### Blog Entries

- [MBS FileMaker Plugin, version 13.3pr1](https://www.mbsplugins.de/archive/2023-06-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [CURL Custom Function](https://www.mbsplugins.de/archive/2022-12-12/CURL_Custom_Function/monkeybreadsoftware_blog_filemaker)
- [Translating Insert from URL options for CURL to MBS Plugin calls](https://www.mbsplugins.de/archive/2020-12-14/Translating_Insert_from_URL_op/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 8.5pr6](https://www.mbsplugins.de/archive/2018-11-08/MBS_FileMaker_Plugin_version_8/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 7.2pr1](https://www.mbsplugins.de/archive/2017-04-03/MBS_FileMaker_Plugin_version_7/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 6.3pr5](https://www.mbsplugins.de/archive/2016-07-04/MBS_FileMaker_Plugin_version_6/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 5.2pr4](https://www.mbsplugins.de/archive/2015-06-24/MBS_FileMaker_Plugin_version_5/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 15th June 2015 , last changed 8th July 2023

  
[CURL.GetResponseCode](CURLGetResponseCode.md) - [CURL.GetResultAsData](CURLGetResultAsData.md)

[HTML Version](CURLGetResultAsContainer.shtml)