Skip to main content
Edited after the comment when user was trying to use name-space.visualforce.com in lightning component
Source Link
7'7'
  • 380
  • 1
  • 10

So as per your updated question and requirement of lightning component to view/load/download any kind of file in browser then you should get respective Content Version of the file you wish to view/download and form a URL.

If it is coming from an sobject record then get the contentDocumentId from the contentDocumentLink record whose linkedEntityId will be recordID. After you get ContentDocumentID, get the latest ContentVersion or number of versions as per requirement and form the URL like this

https://yourDomain.lightning.force.com/sfc/servlet.shepherd/version/download/ContentVersionId

If you want the file to be executed/viewed in browser go to File Upload and Download Security and choose that particular type of file and set the behavior. enter image description here

UPDATE-- You cannot use a URL of

name-space.visualforce.com

in a lightning component. If you wish to preview/download a file uploaded in documents(classic), get that file in lightning either by uploading it manually(if single file or 2) in files tab or a customised code to convert attachment to contentDocument and Version and then get it's ID to use in Lightning component

You can only form the URL i mentioned

https://yourDomain.lightning.force.com/sfc/servlet.shepherd/version/download/ContentVersionId

which has lightning.force.com in your lightning component along with Content version id to preview/view/download following the above procedure.

So as per your updated question and requirement of lightning component to view/load/download any kind of file in browser then you should get respective Content Version of the file you wish to view/download and form a URL.

If it is coming from an sobject record then get the contentDocumentId from the contentDocumentLink record whose linkedEntityId will be recordID. After you get ContentDocumentID, get the latest ContentVersion or number of versions as per requirement and form the URL like this

https://yourDomain.lightning.force.com/sfc/servlet.shepherd/version/download/ContentVersionId

If you want the file to be executed/viewed in browser go to File Upload and Download Security and choose that particular type of file and set the behavior. enter image description here

So as per your updated question and requirement of lightning component to view/load/download any kind of file in browser then you should get respective Content Version of the file you wish to view/download and form a URL.

If it is coming from an sobject record then get the contentDocumentId from the contentDocumentLink record whose linkedEntityId will be recordID. After you get ContentDocumentID, get the latest ContentVersion or number of versions as per requirement and form the URL like this

https://yourDomain.lightning.force.com/sfc/servlet.shepherd/version/download/ContentVersionId

If you want the file to be executed/viewed in browser go to File Upload and Download Security and choose that particular type of file and set the behavior. enter image description here

UPDATE-- You cannot use a URL of

name-space.visualforce.com

in a lightning component. If you wish to preview/download a file uploaded in documents(classic), get that file in lightning either by uploading it manually(if single file or 2) in files tab or a customised code to convert attachment to contentDocument and Version and then get it's ID to use in Lightning component

You can only form the URL i mentioned

https://yourDomain.lightning.force.com/sfc/servlet.shepherd/version/download/ContentVersionId

which has lightning.force.com in your lightning component along with Content version id to preview/view/download following the above procedure.

Source Link
7'7'
  • 380
  • 1
  • 10

So as per your updated question and requirement of lightning component to view/load/download any kind of file in browser then you should get respective Content Version of the file you wish to view/download and form a URL.

If it is coming from an sobject record then get the contentDocumentId from the contentDocumentLink record whose linkedEntityId will be recordID. After you get ContentDocumentID, get the latest ContentVersion or number of versions as per requirement and form the URL like this

https://yourDomain.lightning.force.com/sfc/servlet.shepherd/version/download/ContentVersionId

If you want the file to be executed/viewed in browser go to File Upload and Download Security and choose that particular type of file and set the behavior. enter image description here