Forum Discussion

Yossis's avatar
Yossis
Guide
10 years ago

Retrieve attachment via REST API

Hi

 

We are trying to retrieve message attatchments using the REST API.

 

This solution isn't acceptable because we can't make all attachments public.

 

Is there a way, using the API authentication, to retrieve actual attachment data?

    • Yossis's avatar
      Yossis
      Guide

      I can find the url value. But direct requests to the url do not allow download

  • Hi Yossis,

     

    You need to create custom component to display attachment if user is registered user. Please follow the below code which can be inserted into the forum message quilt:-

     

    <#assign AttachedFile = rest("/messages/id/${env.context.message.id}/uploads/attachments").attachments.attachment />
    <#list AttachedFile as file>
    <#if !user.anonymous>
    <a class="lia-link-navigation attachment-link" href="${file.url}">${file.title} &rlm;${(file.content.size?number/1024)?round} KB</a>
    <#else>
    <a class="lia-link-navigation attachment-link" href="/t5/user/userloginpage">${file.title} &rlm;${(file.content.size?number/1024)?round} KB</a>
    </#if>
    </#list>

     

    Regards,

    Vishwajit Shinde.