Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

I am trying to create a new Attachment for a Confluence page but have been unsuccessful

Matt
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 Champions.
May 13, 2020

Using the Java API in ScriptRunner/groovy I am trying to retrieve all attachments for a page and then create a new one if it currently does not exists.

Everything is working so far, except the creation of the new attachment.  Clearly, I'm missing something and community insight would be super helpful! I'm fairly new to Java/ScriptRunner/Groovy programming.
 
Code:

Attachment newFile = new Attachment("filename.csv", "text/csv", 6014, "new file");


Per: https://docs.atlassian.com/atlassian-confluence/6.0.3/com/atlassian/confluence/pages/Attachment.html, that should be all that is needed to construct a new Attachment object. 

Once the attachment is created I would use AttachmentManager to save the file to the page with content from InputStream/ByteArray.

Does the file/content actually need to exist on the server somewhere before I can create the attachment and save to the page?

However, I receive the following errors in the log. <snippet>


org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-only at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:873) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:710) at jdk.internal.reflect.GeneratedMethodAccessor80.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:205) at com.sun.proxy.$Proxy75.commit(Unknown Source)

 

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events