Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to upload files via a plugin?

D. Brutscher
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.
July 9, 2015

Hi,

I need to batch upload files located on the Confluence server (or some where else in the filesystem if possible) and create attachments within Confluence using a plugin, can anybody give me a hint how to achieve the upload?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
xpauls
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.
July 10, 2015

This will send events

//store attachment
//pdf is byte array (byte[])
AttachmentResource resource = new InputStreamAttachmentResource(new ByteArrayInputStream(pdf), filenameX, "application/pdf", pdf.length, "");
fileUploadManager.storeResource(resource, page);
//attachment is stored. to get info about attachment.
Attachment attachment = page.getAttachmentNamed(filenameX);

 

To avoid sending events (which may provoked NPE in some cases) you can set it to a minor edit:

//store attachment
//pdf is byte array (byte[])
AttachmentResource resource = new InputStreamAttachmentResource(new ByteArrayInputStream(pdf), filenameX, "application/pdf", pdf.length, "", true);
fileUploadManager.storeResource(resource, page);
//attachment is stored. to get info about attachment.
Attachment attachment = page.getAttachmentNamed(filenameX);

 

JavaDoc

jibranbala December 15, 2015

Hi Pauls.. when i attach files via plugin, the page shows attachment and provides the link for attachment. But actually there is no attachment stored in the file system and the link is broken. It shows the following error: "The attachment you were trying to download could not be found in the attachment file store. Either the file has been deleted manually or there was an error in removing the record of the attachment from Confluence." If attachment is not stored, why is it showing in page. And what am i doing wrong!!! I simply used your 3 lines of code and i am also able to get attachmentId in plugin after uploading the file. Thanks

TAGS
AUG Leaders

Atlassian Community Events