Store temporary files

Eugen Mayer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 21, 2013

What is the intended way to store temporary files? Is there an API and if no, how would i ensure "cleanup"? Thank you

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Answer accepted
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 22, 2013

Just use the JVM's configured "temp" directory; this is configured to point to the correct location.

An easy way to do this would be to use the File.createTempFile method, for example.

EDIT: My original answer above is wrong! You should use the temp directory that is create in the Confluence data directory (also referred to as the Confluence "home" directory). You can build a path to this folder with the following code:

File tempDirectory = new File(bootstrapManager.getConfluenceHome(), ConfluenceHomeGlobalConstants.TEMP_DIR);

There is a scheduled job in Confluence that runs once a day to clean up old files in this directory.

Eugen Mayer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 22, 2013

interesting. but what about those temp folders for plugins and how to use PluginDirectoryProvider? I mean, all those things are just nonsense?

Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 22, 2013

They're not nonsense, they're just not intended for you to use - they're part of the way the plugin framework extracts and loads your plugin into the host application.

Eugen Mayer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 22, 2013

Thank you for helping me.

Ok just some simple quesions, so i get those things straight:

- so there is no special tmp folder for a plugins (storage like /plugins/myplugin/temp)
- i should not use BootstrapManager::getConfluenceHome() + "/temp" for tmp folder, since that could be reconfigured, right?
- the temp folder configured with the JVM is the one getting cleaned up by confluence, right?

Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 23, 2013

Actually, I'm sorry I've steered you in the wrong direction here! My recollection was different to the actual code, which I've now looked into.

The temporary directory you should be using is _not_ the JVM-configured temp directory, but the temp directory in the Confluence data directory. The JVM-configured temp directory will be the temp directory of the application server for the Confluence webapp, so it's probably going to be something like "${TOMCAT_INSTALLATION_DIR}\temp".

There's nothing wrong with using's the app server's temp directory, but if you use the Confluence temp directory, there is a scheduled job that runs within Confluence that automatically cleans up old files once a day.

So you're right, you should use "BootstrapManager::getConfluenceHome() + "/temp".

You shouldn't put anything in the "/plugins" folder, since this folder is where the plugin framework runs from and you might confuse it by putting random files in there.

Apologies for the confusion! I'll update my original answer for anyone else who comes across this in the future.

Eugen Mayer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 23, 2013

glad we put that right, thank you very much! I already testing it, work perfect/

Eugen Mayer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 23, 2013

Sorry, but just to have this all together, iam doing this for dependency injections (spring) for BoostrapManager, but later on i get a nullpointer exception on this.bootstrapManager ... its not early in the bootphase, so it should work. Any idea here? Do i need to add anything in the atlassion-plugin.xml?

private BootstrapManager bootstrapManager;

    public void setBootstrapManager(BootstrapManager bootstrapManager) {
        this.bootstrapManager = bootstrapManager;
    }

if i use this before using it, it works..but thats not the intended way:

BootstrapManager bootManager = (BootstrapManager) ContainerManager.getComponent("bootstrapManager");

<body></body>
Royce Wong
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 17, 2015

bootstrapManager.getConfluenceHome() has been deprecated since Confluence 5.5. Use bootstrapManager.getLocalHome() instead. See https://docs.atlassian.com/confluence/latest/com/atlassian/confluence/setup/BootstrapManager.html#getLocalHome%28%29

0 votes
Eugen Mayer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 22, 2013

i could of course use BootstrapManager::getConfluenceHome() + "/temp" ... but that sounds pretty wrong. Could someone at least tell me if this is best practice?

0 votes
Eugen Mayer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 22, 2013

i stumbeled uppon PluginDirectoryProvider and thought its auto-wired using spring, but thats not happening. How woould i user any (central) ?singleton? to get an object implementing this interface for (my) plugin?

It cant be that hard saving files into a temporary folder, or?

I really cant find anything usefull in the docs at all..

TAGS
AUG Leaders

Atlassian Community Events