S-Drive 3.6 Documentation

getAttachmentURL

Returns a temporary, expiring URL for a single S-Drive file — meant for your own Salesforce-side code (Apex, Visualforce, LWC) to use directly, e.g. to render an image inline on a page or link to a file from a custom component.

How to call this method

global static String getAttachmentURL(String parentId, String fileObjectId, Long timeValue)

global static String getAttachmentURL(String parentId, String fileObjectId, Long timeValue, Map<String,String> requestParameters)

Parameters

Parameter

Type

Required

Description

parentId

String

Yes

Id of the parent object the file belongs to. Accepts both 15- and 18-character Salesforce Id formats.

fileObjectId

String

Yes

Id of the file record to get a URL for. To get an older version's URL instead of the current one, pass that version's file record Id here.

timeValue

Long

Yes

How long the URL stays valid, in seconds (e.g. 60 for one minute).

requestParameters

Map<String,String>

No

Extra request parameters for the URL — most notably response-content-disposition, which controls whether the URL opens the file inline or downloads it. See getAttachmentURLs for the full explanation and examples of open vs. download URLs, which apply here too.

Return value

Returns a String — the URL for the file.

Example

Rendering an image file from S-Drive Account Attachments directly on the Account page:

public with sharing class ExamplePageController {
    private String fileURL = '';

    public ExamplePageController(ApexPages.StandardController controller) {
        Account acct = (Account) controller.getRecord();

        List<cg__AccountFile__c> accountFiles = [
            SELECT Id FROM cg__AccountFile__c
            WHERE cg__WIP__c = false
              AND cg__Content_Type__c = 'image/jpg'
              AND cg__Account__c = :acct.Id
        ];

        if (!accountFiles.isEmpty()) {
            fileURL = cg.SDriveTools.getAttachmentURL(acct.Id, accountFiles[0].Id, 1 * 60); // 1 * 60 = one minute
        } else {
            fileURL = 'http://www.cyangate.com/noimage.jpg';
        }
    }

    public String getFileURL() {
        return fileURL;
    }
}
HTML
<apex:page standardController="Account" extensions="ExamplePageController">
    <apex:image url="{!fileURL}" />
</apex:page>

Add this Visualforce page to the Account page layout, and it displays the account's image file (or a placeholder if none exists) using a URL that expires one minute after the page loads.