3

I need to have the ability to preview a ContentDocument image in a lightning web component. Apparently lightning:fileCard is not available for LWC yet and the navigation mixin solution appears to not work if your lightning component is in a lightning community. There is also no thumbnail preview when you upload the document. Any ideas on a good work around for this? Any idea when/if this feature will be available? I'm currently creating a custom app for a client so I need to be able to say that it either isn't possible or there's a relatively easy way to implement it.

2
  • My use case was slighlty easier - we just loaded the ContentVersion via APEX for JPG/PNG only and then added <img src tags with the servlet URL.
    – zaitsman
    Commented Jul 19, 2019 at 2:39
  • @codermeow did you solve it? Commented Jun 9, 2020 at 22:09

1 Answer 1

1

The NavigationMixin solution should work as well, with minor modification. According to this blog post, rather than using NavigationMixin.Navigate with type argument standard__namedPage and ContentDocumentId, you should be using standard__webPage along with the file URL.

    previewFile(file){
        
        if(!this.usedInCommunity){
            
            this[NavigationMixin.Navigate]({
                type: 'standard__namedPage',
                attributes: {
                    pageName: 'filePreview'
                },
                state : {
                    selectedRecordId: file.ContentDocumentId
                }
            });
        } else if(this.usedInCommunity){
            
            this[NavigationMixin.Navigate]({
                type: 'standard__webPage',
                attributes: {
                    url: file.fileUrl
                }
            }, false );
        }
        
    }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .