Brian Dunning's FileMaker Custom Functions

s3presignedUrl ( method ; bucket ; region ; theFilePath ; expireSeconds ; accessKey ; secretKey ; optionsObj )

Generate a presigned URL to upload/download/delete an object in S3

  Be the first to rate this function Log in to vote

Jason Wood   Jason Wood - Show more from this author
Define Database
https://www.definedatabase.com

  Sample input:
s3presignedUrl ( "PUT" ; "mybucket" ; "ca-central-1" ; "path/file.jpg" ; 60 ; $accessKey ; $secretKey ; "" )
  Sample output:
https://mybucket.s3-ca-central-1.amazonaws.com/path/file.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=abcdefghijklmnopqrstuvwxyz/20251207/ca-central-1/s3/aws4_request&X-Amz-Date=20251207T200028Z&X-Amz-Expires=60&X-Amz-SignedHeaders=host&X-Amz-Signature=5e8fb4554b2c355fc7e259c7c7b4620be46723334115620983234bb8bfef3acb

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

FileMaker custom function to generate a presigned URL to upload/download/delete an object in S3

More info: https://github.com/quarfie/s3presignedUrl_FMFunction

PARAMETERS

method | GET or PUT or DELETE or HEAD
bucket | the bucket name
region | eg: ca-central-1
theFilePath | the full path to the file in the bucket eg: /folder/filename.pdf
expireSeconds | the length of time that the URL will be valid
accessKey | AWS Access Key
secretKey | AWS Secret Key
optionsObj | empty or JSON object containing optional parameters

OPTIONAL PARAMETERS

optional parameters are passed as JSON inside the optionsObj parameter

host | the provider's domain, not required for AWS. Must include the full hostname including the bucket name if required.
token | the session token (e.g., from AWS STS), if your role requires you to include one.

USAGE

Generate a presigned URL with the desired method, then...

GET

You can use Insert From URL to download the object to a container or variable (to download a binary object to a variable in FileMaker, you must add the --FM-return-container-variable cURL option). Alternatively, reference the presigned URL in a web viewer (in an src attribute, for example). Note: You may need to change the CORS settings for your bucket in order to load the object into a web viewer.

PUT

Use Insert From URL with the following cURL options:

"-X PUT -H " & Quote ( "Content-Length: " & $fileSizeInBytes ) & " -H " & Quote ( "Content-Type: " & $contentType ) & " --data-binary @$container -D $responseHeaders"

$contentType is the mime type. For example APPLICATION/PDF or IMAGE/PNG. Having the correct content type stored in S3 is necessary to GET the object into a browser or web viewer. For example, without the content-type header IMAGE/PNG, a PNG file would simply by downloaded rather than displayed.

If the upload was successful, PatternCount ( $responseHeaders ; "200 OK" ) will return True.

DELETE

Use Insert From URL with the following cURL options:

"-X DELETE -D $responseHeaders"

If deletion was successful, PatternCount ( $responseHeaders ; "204 No Content" ) will return True.

HEAD

Use Insert From URL with the following cURL options:

--head

The result will include headers that you may wish to parse out, such as Content-Type and Content-Length. Here's one way to extract a header from the result $result:

Let ([
~header = "Content-Type" ;
~start = Position ( $result ; ~header ; 1 ; 1 ) + Length ( ~header ) + 2 ;
~end = Position ( $result ; "ΒΆ" ; ~start ; 1 ) ;
~value = Middle ( $result ; ~start ; ~end - ~start )
];
~value
)

 

Comments

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 21 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: