You can remove double quotes as attachment is JavaScript variable and the correct syntax is:
component.set("v.imageSrc", "/servlet/servlet.FileDownload?file=" + attachment.Id);
You will need to query the contentLinkDocument records with the EntityId equal to the record Id .
And also ContentLinkDocument will give you Id of the content Document and you will need a query against content document to get the necessary file
SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = '[RECORD ID]'
Then SOQL on ContentDocument
Select Id ,Title from ContentDocument Where ID In :[CONTENTDOCUMENTLIST]
Update
If you use Files or content related object there is a simple event with new lightning namespace which can be used
Here is a sample quick POC
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >
<aura:attribute name="contentId" type="String" default="069B00000015QMwIAM"/>
<lightning:button variant="brand" label="Preview Reciept" onclick="{!c.preview }" />
Note that the default here is the Id of the content document .
The controller code for same is below
({
preview : function(component, event, helper) {
$A.get('e.lightning:openFiles').fire({
recordIds: [component.get("v.contentId")]
});
}
})
Best Answer
Looking at the Data Model of the Content Object as mentioned in this post, it looks like you need to get
Id
of theContentVersion
which is tied to you the ContentDocument record. Also to display Contents, the relative url path should be in below format :Sample code
myApp.app:
controller.js
Apex Class: