How to upload file to confluence?

Hi there,
I want to develop a plugin that use javascript/jquery to upload file via REST API and show a link in my plug in. But I don’t know how to start? Anyone give me a hand ?

Thanks!

Is this for confluence cloud or server?

2 Likes

Hi @adhippokharel,

You can find some relevant information here. Specifically, where the ajax part and multipart part of the request.

Thanks!

Cheers,
Anne Calantog

1 Like

Hi @acalantog,
Thank you for your help!
But in the link you share, how can I get a content Id to upload file ?

Thanks!

For more clearly, I’m develop a plugin with have an xwork page. I have a form for user to upload file.
But I don’t know how to upload file and display the file to user.
Could you please give me an example ?

Hi @adhippokharel,

From javascript, you can try (this is for cloud, but should easily be translatable to server):

AJS.$('meta[name=ajs-content-id]').attr('content');

To know more variables available to your page, what you can do is just try opening up you page, open up chrome DevTools and read through the META tags.

Thanks!

Cheers,
Anne Calantog

Or can use AJS.params.contentId

Thank @acalantog and @sahal.saad.
But the return value is undefined.
My page is an Xwork page which I develop in my plugin, not a Confluence page, so I think this page doesn’t have content id.

Hi, anyone has an idea?

You are not just uploading a file in confluence (although you can). Use a CustomContentEntityObject as an upload holder if you wish.

Hi Panos, is there any document about custom entity that I can use ?
Thank a lot!

https://docs.atlassian.com/confluence/5.8.4/com/atlassian/confluence/core/ContentEntityObject.html