It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Using curl upload file in confluence but got

I want to use api uploading files,but faild.

I use the command

curl -D- -u  $USERNAME:$PASSWORD  -H "Content-Type: multipart/form-data" -F "file=@$1" -F "minorEdit=false"


and Got

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0HTTP/2 401
server: nginx
date: Thu, 08 Jun 2017 01:47:51 GMT
content-type: text/html;charset=utf-8
content-length: 1263
www-authenticate: OAuth realm=""
content-language: en
100 48906  100  1263  100 47643   1154  43549  0:00:01  0:00:01 --:--:-- 44195

Can someone help me?

1 answer

0 votes

Hey eastek_claire,

I have been doing some work recently with the Jira and Confluence API's and I think I can shed some light on whats going on here.

Looking at your curl command it could do with a couple of tweaks to get it working, namely changing of the header being set and the inclusion of a '-X' argument to specify this is a PUT command.
I took the liberty of re-writing this and testing to ensure it works:

curl -D- \
-X PUT \
-H "X-Atlassian-Token: nocheck" \
-F "file=@$1" \
-F "minorEdit=false" \$contentId/child/attachment

The things to note that I have changed:

  1. I have added '-X PUT' to ensure the REST API knows we are uploading a file.
  2. I have changed the header type being passed in the '-H' argument as the API requires this header type otherwise the upload will fail.

One last thing, I assume the 'contentID' portion of your command is being passed from the script you are working on? If this is indeed the case please ensure the value being passed is numerical.

You can find more info on the API's and the available calls along with some helpful examples here: API Examples and here specifically for uploading attachments: API Uploading Attachments.



Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published Thursday in Confluence

Confluence CVEs and common questions

Two vulnerabilities have been published for Confluence Server and Data Center recently: March 20, 2019 CVE-2019-3395 / CVE-2019-3396 April 17, 2019 CVE-2019-3398 The goal of this article is...

302 views 0 12
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you