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
Vishalg89Vishalg89 

Download document from force.com sites

Hi all,

I am trying to download the documents of public folder rfom force.com site. I am using following approach for this.

 

value="{!URLFOR($Action.Document.Download, document.id)}"

 

But It opens the document in new tab and URL is shown in address bar. I want to download this instead of showing in new tab, because I don't want to show URL of the document.

could anyone please help me out.

cloudmaniacloudmania
use this custom link instead "servlet/servlet.FileDownload?file={!Document.Id}"
Vishalg89Vishalg89

when I used this "servlet/servlet.FileDownload?file={!Document.Id}", It gives me the same result

cloudmaniacloudmania

Did you put "/" on the beginning of servlet like "/servlet/...."?

Vishalg89Vishalg89

Yes, I put "/" in the beginning.

Vishalg89Vishalg89

Is it possible to download the document without opening it into new tab?

S DigalS Digal

Use the below line and check. But you need to pass the SelectedVersionId in the link to download. So you need to query the ContentVersion sObject to get the specific ID and pass it in below highlighted context.

 

'/sfc/servlet.shepherd/version/download/{!Id}?asPdf=false'

 

If the document is in PDF format then,

 

'/sfc/servlet.shepherd/version/download/{!Id}?asPdf=true'

 

If it works, mark it as valid solution.

Vishalg89Vishalg89

can you pls give me the example of this solution '/sfc/servlet.shepherd/version/download/{!Id}?asPdf=false'. It didn't work for me. or may be I am using this in a wrong manner!

 

I used this:

 

https://mydomain.force.com/HomePage/servlet.shepherd/version/download/015XXXXXXXXXXX?asPdf=false

 

where  015XXXXXXXXXXX is the Id of document

S DigalS Digal

Hey

 

The above line will work only if you have the documents in Content Object. Iooks like you are using Document Object.

 

Rather you can try the previous suggestion but it will open in new tab since the target is set as _blank for the given url.

 

If you would like to open in the same tab then try to include target attribute in your script and set it as _self or _parent. It will work for sure.

 

Let me know if it works and mark it as solution.

 

Regards

SD

Vishalg89Vishalg89

when I use "_self", it opened in current window instead of downloading document.

Vishalg89Vishalg89

Can the document be downloaded automatically instead of opening in window?

S DigalS Digal

This is how it works. I dont think there is any other way within salesforce.com.

Vishalg89Vishalg89

Is there any way to authenticate that document URL(siteurl): "http://mydomain.force.com/Login/servlet/servlet.FileDownload?file=xyz" using apex code/visualforce page?

 

because my first page is login page and using my custom object values, cookies I am authenticating the website. but if that given document link is hacked then one can access any document of the public folders.

 

for example if following urls is leaked then one can access public documents:

http://pcr-developer-edition.ap1.force.com/sample/servlet/servlet.FileDownload?file=01590000001AKJT

 

so please suggest me a technique to authenticate the site url for document.

Vishalg89Vishalg89

This did not work for me, please post any other solution, if you can.