# Download Zip - Using Customized Download Filenames to Build a Folder Structure

This article demonstrates how to build a folder structure when downloading a SharinPix zip file using a customized filename by means of:

* [A SharinPix Permission record.](#using-customized-filename-in-sharinpix-permission-record-to-build-a-folder-structure-when-downloadin)
* [An Apex class.](#using-customized-filename-in-an-apex-class-to-build-a-folder-structure-when-downloading-a-sharinpix)

## Example: Building a Folder Structure Using Customized Filename Inside a Zip File

Let's suppose we have a list of grocery store branches registered as Account records. Each grocery store has multiple store locations registered as Location records.

Using a [SharinPix Search component](https://docs.sharinpix.com/documentation/lightning-web-component/sharinpix-search), we are retrieving all images from all stores irrespective of the branch and location and identifying each image using a [SharinPix custom label](https://docs.sharinpix.com/documentation/features/user-interface/thumbnail-view-display-infos) displaying the branch name and the location as follows: **branchName/storeLocation**

![](https://2221230591-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5EvYRrLbUyvRh8o1jmMG%2Fuploads%2F17bWnoWvAS6YjUzeHSsf%2Ftest.png?alt=media\&token=aac46b2f-e9f9-4ded-b1da-0a2195c315f1)

{% hint style="info" %}
**Information:**

The above SharinPix custom label has been configured using the following Formula field of type text on the **SharinPix Image object** : <mark style="color:$danger;">`IF( ISNULL(Store__c), 'N/A', Store__r.Account__r.Name &'/'& Store__r.Name)`</mark>

For more information on how to configure SharinPix custom labels, refer to this article: [Thumbnail View - Display Infos](https://docs.sharinpix.com/documentation/features/user-interface/thumbnail-view-display-infos)
{% endhint %}

By using the same custom label as the download filenames in the downloaded zip, we achieve the following folder structure:

![](https://2221230591-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5EvYRrLbUyvRh8o1jmMG%2Fuploads%2F6ILKvVnPtzHVT7sPe0z6%2Ftest.png?alt=media\&token=807607bd-88d2-4a78-b703-29ce42b43593)

![](https://2221230591-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5EvYRrLbUyvRh8o1jmMG%2Fuploads%2FDKG43QFaAmQCnse8bIgt%2Ftest.png?alt=media\&token=7cd5600f-0dac-4c9b-91d1-2df24afd33af)

The following sections demonstrate how to customize the filename to achieve the above folder structure when downloading the zip.

## Using Customized Filename in SharinPix Permission Record to Build a Folder Structure When Downloading a SharinPix Zip

To build a folder structure using a SharinPix Permission record, proceed as follows:

1. Create a text field on the SharinPix Image object that will store the path, delimiting each folder and file by slash (/). For example: *ObjectA/ObjectB/ImageFilename*. *Tip: Formula fields of type text can be used for this purpose.*
2. Copy the field API name of the field storing the path.
3. Create/Edit the SharinPix Permission and paste the field API name in the **Salesforce field on sObject SharinPixImage\_\_c with custom image filename for zip download** parameter as demonstrated below.

![](https://2221230591-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5EvYRrLbUyvRh8o1jmMG%2Fuploads%2FKlythqdSKPBuUTRFphzo%2Ftest.png?alt=media\&token=c29cd070-d584-4d43-b4b6-68a98f6162f0)

4\. Ensure that the other zip abilities (*Download Zip* and *Zip file name* , for instance) are properly configured. For more information on the zip abilities, refer to this article: [Multiple Images download (ZIP) - Out of the box](https://docs.sharinpix.com/documentation/features/download-images/multiple-images-download-zip-out-of-the-box)

5\. Configure the other SharinPix Permission abilities as desired and click on **Save** when done.

6\. Assign the SharinPix Permission to the desired SharinPix component.

{% hint style="success" %}
**Tip:**

For more information on how to create, edit, and assign a SharinPix Permission, refer to this article: [SharinPix Permission object - How to create and assign custom permission?](https://docs.sharinpix.com/documentation/access-and-security/sharinpix-permission-object-how-to-create-and-assign-custom-permission)
{% endhint %}

7\. Go to the SharinPix component and download the zip file. The defined path will be applied to the unzipped folder.

## Using Customized Filename in an Apex Class to Build a Folder Structure When Downloading a SharinPix Zip

To build a folder structure in an Apex method, proceed as follows:

1. Create a text field on the SharinPix Image object that will store the path delimiting each folder and file by slash (/). For example: *ObjectA/ObjectB/ImageFilename*. *Tip: Formula fields of type text can be used for this purpose.*
2. Copy the field API name of the field storing the path.
3. In your Apex method, use the field API name as the value for the **download\_custom\_filename** parameter. *Tip: Do not forget to configure the zip filename using the **download\_filename** parameter.*

The two examples below demonstrate how the ***download\_filename** and* **download\_custom\_filename** are configured in a custom Search and album component.

### Code Snippet for Search Component

```apex
params = new Map<String, Object> {
    'path' => '/search?search_bar=false&q=' + clientInstance.token(query),
    'download' => true,
    'download_filename' => 'Store Search',
    'download_custom_filename' => 'CustomFilename__c'
 };
```

### Code Snippet for Album Component

```apex
Map<String, Object> params = new Map<String, Object> { 
    'download' => true,
    'download_filename' => 'Store Search',
    'download_custom_filename' => 'Store_Path__c'
    'abilities' =>  new Map<String, Object> { 
        'download' => true,
        albumId =>  new Map<String, Object> { 
            'Access' =>  new Map<String, Object> { 
                'see' => true,
                'image_download' => true,
                'image_list' => true,
                'image_upload' => true,
            }
        }
    },
    'Id' => albumId
};
```

{% hint style="success" %}
**Tip:**

For more information on how to customize download filenames, refer to this article:

[Multiple Image download (ZIP) - How to personalize the download filenames](https://docs.sharinpix.com/documentation/features/download-images/multiple-image-download-zip-how-to-personalize-the-download-filenames)
{% endhint %}
