How to get the attachment directory?

I’m doing a compatiblility for jira 10 and the app uses AttachmentPathManager.ATTACHMENTS_DIR to get to the attachment directory which is removed in jira 10. But with the changes to the api there is no alternative to this. The Documentation is telling me to use `getAttachmentDirectory() but this method is not found in any class?! Did somebody found a solution for this problem?
To clearify i need the path to the “data/attachment” directory

Thanks in advance

Hi @StefanBombrowski,
have you tried to reconstruct the path to the attachments directory manually, leveraging Jira’s component access to relevant properties.
You can try to use the JiraHome component to fetch Jira’s data directory and constructs the path to the attachments directory.

import com.atlassian.jira.config.util.JiraHome;
import com.atlassian.jira.component.ComponentAccessor;
import java.nio.file.Paths;

public String getAttachmentDirectory() {
    JiraHome jiraHome = ComponentAccessor.getComponent(JiraHome.class);
    String attachmentsDir = Paths.get(jiraHome.getDataDirectory().getAbsolutePath(), "attachments").toString();
    return attachmentsDir;
}

Chears,
Daniel

With Jira 10 attachments are not guaranteed to be stored on the filesystem, as storing attachments in Amazon S3 is supported as an opt-in for customers.

Therefore apps cannot depend on the filesystem location of attachments, the APIs for accessing the directory paths were removed in Jira 10 for this reason.

When working with attachments on Jira 10 you must stream the attachment content (which could be on the filesystem or in S3) using methods such as AttachmentManager#streamAttachmentContent

1 Like

@rlander the path to the atttachments is stored inside the server file filestore-config.xml. So there should be a way to get that information. My use-case is a restore of the attachments so i need the path to the attachments directory.

@DanielGrabke ̶t̶h̶i̶s̶ ̶i̶s̶ ̶t̶h̶e̶ ̶f̶i̶r̶s̶t̶ ̶p̶a̶r̶t̶.̶ ̶B̶u̶t̶ ̶f̶o̶r̶m̶ ̶t̶h̶e̶r̶e̶ ̶i̶ ̶n̶e̶e̶d̶ ̶t̶o̶ ̶a̶c̶c̶e̶s̶s̶ ̶t̶h̶e̶ ̶d̶a̶t̶a̶/̶a̶t̶t̶a̶c̶h̶m̶e̶n̶t̶ ̶d̶i̶r̶e̶c̶t̶o̶r̶y̶,̶ ̶w̶h̶i̶c̶h̶ ̶w̶a̶s̶ ̶p̶r̶o̶v̶i̶d̶e̶d̶ ̶b̶e̶ ̶t̶h̶e̶ ̶A̶t̶t̶a̶c̶h̶m̶e̶n̶t̶P̶a̶t̶h̶M̶a̶n̶a̶g̶e̶r̶.̶A̶T̶T̶A̶C̶H̶M̶E̶N̶T̶S̶_̶D̶I̶R̶
Looks like thisis the workaround for me. At least for now.

com.atlassian.jira.config.properties.ApplicationProperties#getString with the key jira.path.attachments might get you the directory.

com.atlassian.jira.config.properties.ApplicationProperties#getString was null. Will i go with the solution from @DanielGrabke

Thank you for your help.