Container Drag and Drop From Web Browser/Viewer
Using FileMaker 12 you can drag and drop a file from your desktop into a container field. Unfortunately, doing the same thing from a web browser or the web viewer within FileMaker only yields a URL to the file in question.
Fortunately I came across a technique by Douglas Alder of HomeBase software recently which demonstrated a cool technique on how to use drag and drop from a web browser to place images into a container field using a script trigger and the Insert from URL script step. It didn’t quite meet my needs, so I made some minor modifications to it and thought others could benefit from the changes.
It is important to note that your container field must be set to ‘Optimize for Images’ and not ‘Optimize for Interactive Content’, otherwise you will not be able to drag and drop files onto it.
For those of you who are using FileMaker 13, I have also added a bit of code that is specific to FileMaker v13:
Else If[GetContainerAttribute ( GetFieldName($fn); "Storage Type" ) ≠ "Text"//Verify Data Type]
Please omit this bit of code if you are using FileMaker v12 or earlier since this function does not exist in earlier versions.
SCRIPT
#Improvements:
# Removed file type restrictions to allow for PDFs and other files to be captured.
# Removed the field dependency to allow script to work for any table or field.
#
#Dependencies:
# – Your Container Field should use the OnObjectModify script trigger to run this script.
# – Optional: Pass the Object Name of the Field as the script parameter, otherwise the field object name must be ‘file’.
#
Set Error Capture [On]
# Test Object
Set Variable [$obj; Value:if(Not IsEmpty(Get(ScriptParameter)) ; Get(ScriptParameter) ; "file")]
Go To Object [Object Name:$obj]
If[Get(LastError) ≠ 0]
Show Custom Dialog ["Error: " & Get(LastError):"Unable to locate layout object '"$obj&"'."]
Exit Script[]
End If
#
#Get Container Field Data
Set Variable[$fn ; Value:Get(LayoutTableName) & "::" & get(ActiveFieldName)]
Set Variable[$len ; Value:Length(GetField($fn))]
Set Variable[$txt ; Value:GetAsText(GetField($fn))]
#
#Error Checking
If[Abs(get(SystemPlatform))≠1//Mac Only]
Exit Script[]
Else If[IsEmpty(GetField($fn))//Nothing Exists To Insert]
Exit Script[]
Else If[GetContainerAttribute ( GetFieldName($fn); "Storage Type" ) ≠ "Text"//Verify Data Type]
Exit Script[]
Else If[PatternCount($txt;"://")=0 //No Valid URL Exists]
Exit Script[]
Else If[$len > 1000 //URL Length is too long]
Exit Script[]
End If
#
#Attempt To Insert The File
Insert from URL [Select;No dialog;$txt]
If [Get(LastError) ≠0]
Show Custom Dialog ["Insert URL Error: " & Get(LastError);"Could not insert a file from the URL:" & ¶ & $txt ]
Exit Script[]
End If
Sample File: ContDragNDropOSX.zip