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

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

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

Thanks!! It work!

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 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...

185 views 0 11
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