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

"no json object could be decoded" From uploading an attachment to Confluence Edited

eastek_claire Apr 16, 2017

I want to use confluence rest api to upload my picture.

I read from [here](https://developer.atlassian.com/confdev/confluence-server-rest-api/confluence-rest-api-examples)

Use

curl -v -S -u User:User -H 'X-Atlassian-Token: no-check' -F 'file=@/c/Users/User/a.jpg' -F 'comment=test' http://test.atlassian.net/wiki/display/API/upload | python -mjson.tool

But got the error message 

* timeout on name lookup is not supported
*   Trying 165.254.227.xxx...
* TCP_NODELAY set
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to eastek-ezcam.atlassian.net (165.254.227.242) port 80 (#0)
* Server auth using Basic with user 'User'
> POST /wiki/display/API/upload HTTP/1.1
> Host: test.atlassian.net
> Authorization: Basic ZWFzdGVrX2NsYWlyZTplYXN0ZWtfY2xhaXJl
> User-Agent: curl/7.51.0
> Accept: */*
> X-Atlassian-Token: no-check
> Content-Length: 119370
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------d3c715dd14df444a
>
< HTTP/1.1 301 Moved Permanently
< Server: nginx
< Date: Mon, 17 Apr 2017 02:49:56 GMT
< Content-Type: text/html
< Content-Length: 178
< Connection: keep-alive
< Location: https://test.atlassian.net/wiki/display/API/upload
* HTTP error before end of send, stop sending
<
{ [178 bytes data]
  0  116k  100   178    0     0    335      0 --:--:-- --:--:-- --:--:--   379* Curl_http_done: called premature == 0
  0  116k  100   178    0     0    335      0 --:--:-- --:--:-- --:--:--   379
* Closing connection 0
No JSON object could be decoded

I also try this

curl -T "C:\Users\User\Desktop\a.jpg" "https://test.atlassian.net/wiki/display/API/upload"

and got 

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 25982    0     0  100 25982      0  24465  0:00:01  0:00:01 --:--:-- 24465

But the web (https://test.atlassian.net/wiki/display/API/upload) doesn't have the picture I uploaded..

I also try

curl -D- -u User:User -X POST -H "X-Atlassian-Token: nocheck" -F "file=@a.jpg" http://test.atlassian.net/rest/api/content/52408007/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/1.1 301 Moved Permanently
Server: nginx
Date: Mon, 17 Apr 2017 09:39:40 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: https://test.atlassian.net/rest/api/content/52408007/child/attachment

  0  116k  100   178    0     0    392      0 --:--:-- --:--:-- --:--:--   406<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>

What's worng in my code?

 

1 answer

1 accepted

1 vote
Answer accepted
Maksym Fedoryshyn Atlassian Team Apr 26, 2017

Hi! It seems that your load balancer is configured to use https only. So every time you make a "http://xxx" request, the load balancer redirects you to "https://xxx". Can you please try to use https:// urls instead (for example https://test.atlassian.net/wiki/display/API/upload instead of http://test.atlassian.net/wiki/display/API/upload)? Or you may use "follow redirects" curl option

eastek_claire Apr 26, 2017

Thanks!! It work!

Kirill Karpelson May 31, 2017

Thank you very much, Maksym!!! I think your post is the only place on the internet that actually answers this question! :)

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 in Confluence

6 Awesome Ways to Apply Trello, JIRA and Confluence to your Project

I attended  Atlassian Summit 2019  and learned a lot from the presenters, attendees and knowledgeable Atlassian product managers. The presentations I attended focused on applying Agile, pla...

2,325 views 11 27
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you