I am trying to Preview and download document from LWC, From apex controller i am returning Map<> contains ID and Document name, and iteration that map data in html file and passing map.key value to href url, but dynamic is not populating in URL.
<template for:each={mapData} for:item="mapkey">
Test: {mapkey.key}
<lightning-button-icon key={mapkey} icon-name="utility:download" variant="bare" alternative-text="Settings"></lightning-button-icon>
<a key={mapkey} style="color: #000000" href ="/sfc/servlet.shepherd/document/download/{mapkey.Key}?operationContext=S1" target="_blank" preview= "{mapkey.value}">{mapkey.value}</a>
</template>
JS Code:
.then(data => {
/// var conts = data;
console.log('data map--->'+data);
if(data){
// eslint-disable-next-line guard-for-in
for(let key in data) {
this.mapData.push({value: data[key], key:key}); //Here we are creating the array to show on UI.
}
}
})
Apex Code:
@auraenabled
/* Method will return a Map Contains Document ID and Name */
public static Map<string,string> getUrls( string searchstr){
Map<string,string> contdocidandtitle = new Map<string,string>();
system.debug('searchstr'+searchstr);
For(Document cd :[select id,folderid,name from document where folder.name =:searchstr]){
contdocidandtitle.put(cd.id,cd.name);
}
return contdocidandtitle;
}
Error is: sfc/servlet.shepherd/document/download/%7Bmapkey.Key%7D?operationContext=S1 in URL "mapkey.key" priniting instead of ID Help me with valuable suggestions.