Upload Images with Custom Metadata (Developer-Oriented)

This documentation explains how to pass custom metadata to images uploaded using SharinPix albums.

Adding custom metadata to images may be useful when you need to filter or group the uploaded images by specific metadata. You can add custom metadata to the images you upload either via the web app or the SharinPix Mobile app.

To demonstrate how images can be uploaded with custom metadata, we will:

Generating Token with upload_metadata parameter 

To add custom metadata to images you upload, you must add the upload_metadata to a token generated via code.

The code snippet below shows the upload_metadata parameter projectId => 15 as the value.

'upload_metadata'=> new Map<String,String> {'projectId'=> '15'}
Click to copy

Note: 

The upload_metadata parameter is of type Map<String, T> where T is can be any other type.

Upload metadata parameter in Album token

Adding the upload_metadata parameter to an album token will add the custom metadata specified to images uploaded on that album.

The code snippet below shows the upload_metadata parameter in a custom album token.

public String generateToken(Id recordID) {
 sharinpix.Client clientInstance = sharinpix.Client.getInstance();
 String token = clientInstance.token(
     new Map<String, Object> { 
         'upload_metadata' => new Map<String, String> { 'projectId' => '15' }
         'Id' => recordID,
         'path' => '/pagelayout/' + recordID,
         'abilities' => new Map<String, Object> {
             recordID => new Map<String, Object> {
                 'Access' => new Map<String, Boolean> {
                     'see' => true,
                     'image_list' => true,
                     'image_upload' => true
                 }
             }
         }
     }
 );
 return token;
Click to copy

You can find other ways to generate album tokens in this article, which is called Online Token Generation.

Tip: 

If you have an existing SharinPix Album Permission, follow the article Generate token from SharinPix Permission with Apex to add the upload_metadata parameter to that permission.

Upload metadata parameter in Mobile token

Adding the upload_metadata parameter to a mobile token will add the custom metadata to images uploaded using the SharinPix Mobile App.

The code snippet below shows the upload_metadata parameter in a custom mobile token.

String token = sharinpix.Client.getInstance().token(
                new Map<String, Object> {
                    'user_id' => UserInfo.getUserId(),
                    'email' => UserInfo.getUserEmail(),
                    'album_id' => id,
                    'name' => '',
                    'exp' => 0,
                    'upload_metadata'=> new Map<String,String> {'projectId'=> '15'}
            );
            
// Save token value in Salesforce field
Click to copy

You can find other ways to generate mobile tokens in the article Mobile token generation.

Using custom token with upload_metadata parameter on SharinPix Components

You can use your custom token containing the upload_metadata parameter on the SharinPix Album component or SharinPix mobile component such as the SharinPix Mobile Launcher component. You can follow this article on how you can use your custom token in an Album component via code.

Once you have your custom token in one of the components, uploading images using either components will add your custom metadata to the images

SharinPix Image Object with custom metadata

If you want to access the value given to the upload_metadata parameter as part of a Salesforce field, you will need:

You can follow the article Enable Image Sync for Lightning on how to view SharinPix Image Records.

The value given to the upload_metadata parameter is added to the Metadatas field of a SharinPix Image object, as shown in the screenshot below.

0 Comments

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.