Forums

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

Using curl upload file in confluence but got

eastek_claire June 7, 2017

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" https://test.atlassian.net/wiki/rest/api/content/contentID/child/attachment

 

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="https%3A%2F%2Feastek-ezcam.atlassian.net%2Fwiki"
content-language: en
100 48906  100  1263  100 47643   1154  43549  0:00:01  0:00:01 --:--:-- 44195

Can someone help me?

2 answers

1 vote
Battlebeard
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 22, 2018

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- \
-u $USERNAME:$PASSWORD \
-X PUT \
-H "X-Atlassian-Token: nocheck" \
-F "file=@$1" \
-F "minorEdit=false" \
https://test.atlassian.net/wiki/rest/api/content/$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.

Best,

Nero

samarth adhikari November 4, 2021

trial.PNG

Hi I tried what you suggested but got this. No image has been posted. I tried with POST too but that also didn't go through. What must be done?

0 votes
Tommaso Scorteccia December 12, 2019

Hi,

I try to use the same procedure but I don't see the file on the page...

This is my code

 

curl -D- \
-u user:password \
-X PUT \
-H "X-Atlassian-Token: nocheck" \
-F "file=@esempio.txt" \
-F "minorEdit=true" \
-F "comment=Example attachment comment" \
http://confluence.website.it:8190/rest/api/content/12255634/child/attachment

 

and this is the reply

 

HTTP/1.1 405 

X-ASEN: SEN-13959260

Set-Cookie: JSESSIONID=25A9555B1E5E3BCA2B1D5790CD75DFA0; Path=/; HttpOnly

X-Seraph-LoginReason: OK

X-AUSERNAME: Tommaso

Allow: HEAD,POST,GET,OPTIONS

X-Content-Type-Options: nosniff

Content-Length: 0

Date: Thu, 12 Dec 2019 16:06:07 GMT

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, confluence whiteboards, whiteboard templates, template contest, visual collaboration, atlassian learning, confluence community, brainstorming tools, agile planning, team productivity, confluence templates, share your template

Share Your Confluence Whiteboard Template for a Chance to Be Featured in the Product! 🏆

Want to leave your mark on Confluence? One winner will have their whiteboard design added into Confluence for all users to access! This is your chance to showcase your creativity, help others, and gain recognition in the Confluence community.

Share your template today!
AUG Leaders

Atlassian Community Events