curl.file2var ( )

Function stats

Average user rating
37
419
9999
Support
FileMaker 10.0 +
Date posted
01 February 2019
Last updated
01 February 2019
Version
Recursive function
No

Author Info
 Fabrice

79 functions

Average Rating 4.4

author_avatar



 

Function overview

Prototype

curl.file2var  ( _file )


Parameters

_file  a container (or variable with a file)


Description

Tags:  Variables   curl   container  

because curl options support @$var for files but as a result the file is named after the variable,
this function declares a variable named after the filename that contains the file
the result is the variable name so you can use it in the curl options definition as

"-T " & curl.file2var ( $myFile )
or -F "\"attachments=@" & curl.file2var ( $myFile ) & "\""

Examples

Sample input

"-T " & curl.file2var ( $myFile )


Sample output

-T $aNicePicture.jpg

 

Function code

/*
curl.file2var ( _file )
by Fabrice Nordmann, 1-more-thing

v1
    Jan 2019


because curl options support @$var for files but as a result the uploaded file is named after the variable,
this function declares a variable named after the filename that contains the file
the result is the variable name so you can use it in the curl options definition as

"-T " & curl.file2var ( $myFile )
or -F "\"attachments=@" & curl.file2var ( $myFile ) & "\""


*/



Case ( not IsEmpty ( _file ) ;
Let ([
    $cf2v.file = _file ; // needed in the evaluation
    // replace forbidden characters
    $cf2v.varName = Substitute ( GetContainerAttribute ( _file ; "filename" ) ; [ "/" ; "_" ] ; [ " " ; "_" ] ; [ "-" ; "_" ]) ;
    // FileMaker var name support digit as first character, but curl implementation doesn't.
    $cf2v.varName = Case ( not IsEmpty ( Filter ( Left ( $cf2v.varName ; 1 ) ; "0123456789." )) ; "_" ) & $cf2v.varName ;
    // Variable names are also limited to 100 char including $, let's shorten it by the middle
    $cf2v.varName = Case ( Length ( $cf2v.varName ) > 99 ; Left ( $cf2v.varName ; 50 ) & Right ( $cf2v.varName ; 49 ) ; $cf2v.varName ) ;
    // declare the variable
    void = Evaluate ( "Let ( $" & $cf2v.varName & "=$cf2v.file ; \"\" )" ) ;
    // store the result and clean up
    r = "$" & $cf2v.varName ;
    $cf2v.varName = "" ;
    $cf2v.file = ""
];
    r
)
)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/419

    Prototype: curl.file2var( _file )
    Function Author: Fabrice (http://www.fmfunctions.com/mid/37)
    Last updated: 01 February 2019
    Version: 1.2

*/
// ===================================

 

 

 

 

 

 

 

Top Tags

Text Parsing  (33)
List  (32)
Date  (28)
XML  (27)
Format  (23)
Sql  (22)
Dev  (20)
Debug  (17)
Interface  (15)
Layout  (15)
Text  (14)
Variables  (13)
Filter  (12)
Layout Objects  (11)
Design  (10)
Array  (8)