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
Medhavi SharmaMedhavi Sharma 

How to download pdf using publicURL in lightning component?

Hi,

I have created a lightning component accordion where I want to display a link to download a pdf file publicly(that exists in database). I am querying ContentDistribution to get the URL. Can someone help me on how to proceed at the client side? 

db query : select ContentDownloadUrl from ContentDistribution

How do I assign this link in the component?

Thanks in advance for your help

Khan AnasKhan Anas (Salesforce Developers) 
Hi Medhavi,

Greetings to you!

Please refer to the below links which might help you further with the above requirement.

https://salesforce.stackexchange.com/questions/148568/how-to-download-file-lightning-component

https://salesforce.stackexchange.com/questions/209135/download-fileimage-doc-pdf-in-lightning-component?rq=1

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Medhavi SharmaMedhavi Sharma

Hi khan,

This link helps in downloading files stored in documents.

I want download the pdf using the ContentDownloadUrl, DistributionPublicUrl. I just want to fire this URL when the user clicks a button.

Thanks. 

Raj VakatiRaj Vakati
You can create an Vf page with the output link 

and click of the link redirect download 
 
<apex:outputlink value="{!ContentURL}">File</apex:outputlink>
 
Apex (Hard coded document): 

public PageReference getContentURL() { 

 ContentVersion []cv=[select id, ContentDocumentId from ContentVersion where contentdocumentid='06930000000TnHP']; 

return new PageReference('/' + cv[0].id);