Salesforce

Using Images in Integrations

« Go Back
Information
Using Images in Integrations
using-images-in-integrations-af-base64
Article Details

Introduction

Images that have been uploaded as part of a form submission can be incorporated in integrations using  @af:base64($token:$num). Please note that you cannot use this in the message of an email integration.

Method

$token  ? the upload field token

:$num ? Integer 1-n (optional) if there are multiple files this number defines the index of the file

Note: Only works in integrations v2 (NB to use V2 on Submission integrations you will require new queue processor to be enabled)

By using this function, you'll pass a Base64 encoded string instead which you can write to a database or similar. 

Examples

Get file content string

{upload} is the upload type field token  

@af:base64({upload})  - this will return base64 string of the CONTENT of the first uploaded file 
@af:base64({upload:1}) -  this will return base64 string of the CONTENT of the first uploaded file
@af:base64({upload:2}) - this will return base64 string of the CONTENT of the second uploaded file
@af:base64({upload:4})  -this will return base64 string of the CONTENT of the fourth uploaded file

The output will be in format  data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=


Get raw file content string

Used to return only the base64 string with no tags or prefixes.

{upload}

is the upload type field token  

@af:base64source({upload})  - this will return only the base64 string of the CONTENT of the first uploaded file 
@af:base64source({upload:1}) -  this will return only the base64 string of the CONTENT of the first uploaded file
@af:base64source({upload:2}) - this will return only the base64 string of the CONTENT of the second uploaded file

The output will be in format  R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=


Get file name 

{upload} is the upload type field token
{text1} is the text type field token 

@af:base64({text1}{upload}) - this will return base64 string of ( {text1} token + the NAME of the uploaded file ) 
@af:base64({text1}{upload:3})  - this will return base64 string of ( {text1} token + the NAME of the third uploaded file ) 

The output will be in format  base64_encode( 'mytext' + 'picture.jpg' )  => AIUEHBROSRWMCNXINDYJSIA234d=


Get normal string encoded 

{text1} is the text type field token 

@af:base64({text1}) -  this will return base64 string of ( {text1} token ) 

The output will be in format  base64_encode( 'mytext' )  => 73UYE09PSDASDSIA234d=


Get Filename

{upload}  is the upload type field token    -> fileName = picture.jpg
! character  is to avoid the base64_encoding of the result 

@af:base64({upload1:1}!)   - this will return the FILE NAME of the file, in this case 'picture.jpg  


To reproduce the image within a printable

use the following format in the printable source code: 

 <img src="@af:base64({upload1})" />

ie where {upload1} is the data name for the relevant image
(note cannot be used in emails)


Using @af:if with multiple @base64({upload})token in data base integrations

 @af:if({noOfFiles}='1') insert into Files values ( '@af:base64({uplUploadFiles:1})' ); @endaf:if  @af:if({noOfFiles}='2') insert into Files values ( '@af:base64({uplUploadFiles:1})' ), ( '@af:base64({uplUploadFiles:2})' ); @endaf:if
     

    Further useful reading:

     

    top of page

    •  base64 won't retrieve the name of an upload when it is in a subform, it does seem to correctly generate the base64 though. If you have one file in the upload, you can pull the file name out of the subform and into an external field by using {subformName/uploadFieldName} as a default value.
    • If you have added multiple files to one upload in a subform, then it returns all names of the files into one text string (e.g. upload1.jpg, upload2.jpg, upload3.jpg).  
      Adding separate text fields for each "upload name" and running an integration to split these values out into these new values is possible. Though it is extra effort, it will allow you to check to see if an upload exists if multiple are used.

      In the subform, create:
      a text field called "SubformUploadNames" with the dataname of "SubformUploadNames"
      and a default value of "{upload:value_label}" (where "upload" is the data name of your upload field).

      An example of a MySQL script to achieve this is below:-

       
      SELECT 
      {{    -- Extract the first value}}
      {{    IFNULL(NULLIF(SUBSTRING_INDEX({SubformUploadNames}, ',', 1), ''), NULL) AS first_value,}}

      {{    -- Extract the second value}}
      {{    IF(}}
      {{        LENGTH({SubformUploadNames}) - LENGTH(REPLACE({SubformUploadNames}, ',', '')) < 1,}}
      {{        NULL,}}
      {{        SUBSTRING_INDEX(SUBSTRING_INDEX({SubformUploadNames}, ',', 2), ',', -1)}}
      {{    ) AS second_value,}}

      {{    -- Extract the third value}}
      {{    IF(}}
      {{        LENGTH({SubformUploadNames}) - LENGTH(REPLACE({SubformUploadNames}, ',', '')) < 2,}}
      {{        NULL,}}
      {{        SUBSTRING_INDEX(SUBSTRING_INDEX({SubformUploadNames}, ',', 3), ',', -1)}}
      {{    ) AS third_value,}}

      {{    -- Extract the fourth value}}
      {{    IF(}}
      {{        LENGTH({SubformUploadNames}) - LENGTH(REPLACE({SubformUploadNames}, ',', '')) < 3,}}
      {{        NULL,}}
      {{        SUBSTRING_INDEX(SUBSTRING_INDEX({SubformUploadNames}, ',', 4), ',', -1)}}
      {{    ) AS fourth_value,}}

      {{    -- Extract the fifth value}}
      {{    IF(}}
      {{        LENGTH({SubformUploadNames}) - LENGTH(REPLACE({SubformUploadNames}, ',', '')) < 4,}}
      {{        NULL,}}
      {{        SUBSTRING_INDEX(SUBSTRING_INDEX({SubformUploadNames}, ',', 5), ',', -1)}}
      {{    ) AS fifth_value;}}

    • Note: repeatable sub forms using one upload field with multiple images will not work with this approach.

    Powered by