【发布时间】:2020-08-05 14:33:51
【问题描述】:
Facing issue with retrieving image on Salesforce Community page,
I had tried the same community image url on chrome, ie and mozilla browser.
But, this will work fine on LWC component when i am posting it on app page then image is displaying properly. ie image preview work fine on the app page but not on the community view.
我也尝试过提供自定义 URL,但问题仍然存在。 当我右键单击显示在社区中的小图像图标并复制图像 url 并将其发布到浏览器上时,它向我显示了作为该帖子的附加屏幕截图提供的错误。
For more detail description on inspect element it was giving : error code - 503
---- .cls code ----
@AuraEnabled(cacheable=true)
public static List<ContentDocument> retriveFiles(String ticketId)
{
system.debug('ticketId line 10 ' + ticketId);
List<ContentDocumentLink> listContentDocumentLink = [SELECT
ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId =:ticketId
LIMIT 1];
if (!listContentDocumentLink.isEmpty()){
List<ContentDocument> listContentDocument = [SELECT Id, Title,
FileType, FileExtension FROM ContentDocument WHERE Id
=:listContentDocumentLink[0].ContentDocumentId];
if(!listContentDocument.isEmpty()){
system.debug(' listContentDocument[0] ' +
listContentDocument[0]);
return listContentDocument;
}
}
return null;
}
@AuraEnabled
public static List<FileData> GetEntityRecordFiles(string ticketId)
{
system.debug('BASE_URL line 10 ' + BASE_URL);
system.debug('ticketId line 10 ' + ticketId);
List<ContentDocumentLink> links=[SELECT ContentDocumentId,LinkedEntityId
FROM ContentDocumentLink where LinkedEntityId=:ticketId];
Set<Id> ids=new Set<Id>();
for(ContentDocumentLink link:links)
{
ids.add(link.ContentDocumentId);
}
List<ContentVersion> versions=[SELECT
VersionData,Title,ContentDocumentId,FileExtension FROM ContentVersion WHERE
ContentDocumentId = :ids AND IsLatest = true];
List<FileData> files=new List<FileData>();
for(ContentVersion attach:versions)
{
FileData data=new FileData();
if(versions!=null && versions.size()>0)
{
data.Content =
EncodingUtil.base64Encode(versions[0].VersionData);
data.ContentType = ContentType(versions[0].FileExtension);
}
data.DownloadUrl =
'/sfc/servlet.shepherd/document/download/'+versions[0].ContentDocumentId;
data.FileUrl = '/sfc/servlet.shepherd/version/renditionDownload?
rendition=THUMB720BY480&versionId='+versions[0].Id;
this.relatedImageData.push({ Id: img.Id, url:
'/sfc/servlet.shepherd/version/download/' + versions[0].Id});
files.add(data);
}
return files;
}
--CODE IN .html File------
<template for:each={files} for:item="keyValue" >
<tr key={keyValue.Id}>
<template if:true={keyValue.DownloadUrl}>
<img src={keyValue.DownloadUrl}/>
</template>
</tr>
</template>
--CODE IN .js File -----
filePreview(event) {
// Naviagation Service to the show preview
this[NavigationMixin.Navigate]({
type: 'standard__namedPage',
attributes: {
pageName: 'filePreview'
},
state : {
// assigning ContentDocumentId to show the preview of file
selectedRecordId: event.currentTarget.dataset.id
}
})
}
[![报告错误][1]][1]
[1]: https://i.stack.imgur.com/WOjSv.png
【问题讨论】: