function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Salvatore MignognaSalvatore Mignogna 

Download a PDF not showing the servlet link



I need to provide the secure download of a pdf stored on salsforce platform as attachment whithout showing the direct link to the resource (i.e. /servlet/servlet.FileDownload?file=........).


Assuming that a user has the right to access the pdf, is there a way to download the resource without provide the direct link?


As per my knowledge it is not possible. Workaround may be to send the logged in user an email with the attachment. To add some flexibility you may prompt the user to provide preferred email id in your page.

I have found one workaround for you. See the below mentioned code. Till now I am able to do this for text files only. I will check if I can manage to make it work for other mime types. 
<apex:page controller="downloadMyFileController">
<apex:includeScript value="{!URLFOR($Resource.filesaver)}"/> <script src="/soap/ajax/28.0/connection.js"/> <script type="text/javascript"> sforce.connection.sessionId = '{!$Api.Session_ID}'; var qr = sforce.connection.query("Select Id, Body, Name From Attachment Where Id = '{!fileId}'") ; var records = qr.getArray("records"); saveAs(new Blob([sforce.Base64Binary.prototype.decode(records[0].Body)], {type: 'text/plain;charset=utf-8;charset=utf-8'}), 'file.txt'); </script> </apex:page>


public with sharing class downloadMyFileController {
    public Id fileId{get;set;}
    public Attachment at{get;set;}
    public DownloadMyFileController()
        fileId = ApexPages.currentPage().getParameters().get('id');
        at = [Select Id, Body, Name From Attachment Where Id = :fileId];

Salvatore MignognaSalvatore Mignogna

Thanks a lot,


I'll try to extend the solution for other mime types. I need to download pdf files.