【问题标题】:Image display Issue into community Salesforce图像显示问题到社区 Salesforce
【发布时间】: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

【问题讨论】:

    标签: salesforce-lightning


    【解决方案1】:

    基本答案是:社区的主机与 salesforce 应用不同。

    您基本上是在使用适用于 salesforce 应用程序但不在社区中的 URL hack,因为社区不会公开 /sfc/servlet.shepherd/...

    如果我没记错的话,你可以在社区中使用/servlet/servlet.FileDownload?file={fileId}

    否则你可以尝试获取之前添加的salesforce应用的base url:https://...../sfc/servlet.shepherd/...

    请注意,社区登录和 salesforce 登录并不总是相同的,因此您可能还会遇到身份验证问题。

    如果我理解正确,您是在尝试在社区中显示文件的缩略图吗?我们在 Salesforce 应用程序中使用“Lightning Image Slider”AppExchange,我想知道它是否适用于社区并供您使用。

    编辑:添加社区链接

    【讨论】:

    • 如何找到downloadURL、fileURL的完整URL?
    【解决方案2】:

    我建立了一个社区网站。我通过您的方法显示了文件 priview。它对“内部”用户运行良好。但是 priview 对社区许可证用户给出了错误。 以下解决方法对我有用

    1. contentVersion上写一个触发器。在'插入后'触发器中,在'ContentDistribution'对象中创建对应的记录,

    2. PdfDownloadUrlDistributionPublicUrl 字段自动填充 contentDistribution。

    3. 使用此链接查询此对象并显示文件预览。

    谢谢

    【讨论】:

      猜你喜欢
      • 2021-01-05
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多