We have a Lightning Component where a User uploads a file (Excel, Word, Image) and then the page will update with a preview of the file.
We are using ContentVersion/ContentDocumentLink to store the file. After the file in inserted, we would display it using:
<img src="{!'/sfc/servlet.shepherd/version/download/'+ v.LatestPublishedVersionId }" />
This worked well for images, but not for any other file type.
So I looked into:
<img src="{!'/sfc/servlet.shepherd/version/renditionDownload?rendition=THUMB720BY480&versionId='+ v.LatestPublishedVersionId }" />
This was nice. All file types get a preview.
But! The first rendering immediately after the upload always shows a 'missing/broken image' type icon. The preview only would correctly appear after reloading the page, a few seconds later. This seems to only be happening for non-image type file, so I guess there is a conversion process that takes a few seconds to complete.
Any suggestions on how to handle this?
I dont have a lot of experience with JavaScript, but an artificial pause seems like it may be a bad idea. Is there a way to tell when the renditionDownload is available? Or is there a better way to preview the files?