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

addAttachment JSON

I'm trying to attach a file to an existing page, the json code is below:

{"jsonrpc" : "2.0", "method" : "addAttachment", "params" : [19791898 , "{"fileName" : "image.jpg", "contentType" : "image/jpeg", "comment" : "to be ignored anyway"}" , "aBinaryObj" ], "id" : 15466905}

I got the below error:

{"id":null,"error":{"message":"The request body could not be parsed as JSON.","data":"org.codehaus.jackson.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 0)): has to be escaped using backslash to be included in string value\n at [Source: org.apache.catalina.connector.CoyoteReader@bd9c24; line: 1, column: 178]\norg.codehaus.jackson.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 0)): has to be escaped using backslash to be included in string value\n at [Source: org.apache.catalina.connector.CoyoteReader@bd9c24; line: 1, column: 178]\r\n\tat org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1213)\r\n\tat org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:375)\r\n\tat org.codehaus.jackson.impl.JsonParserMinimalBase._throwUnquotedSpace(JsonParserMinimalBase.java:341)\r\n\tat org.codehaus.jackson.impl.ReaderBasedParser._finishString2(ReaderBasedParser.java:760)\r\n\tat org.codehaus.jackson.impl.ReaderBasedParser._finishString(ReaderBasedParser.java:731)\r\n\tat org.codehaus.jackson.impl.ReaderBasedParser.getText(ReaderBasedParser.java:85)\r\n\tat org.codehaus.jackson.map.deser.BaseNodeDeserializer.deserializeAny(JsonNodeDeserializer.java:219)\r\n\tat org.codehaus.jackson.map.deser.BaseNodeDeserializer.deserializeArray(JsonNodeDeserializer.java:201)\r\n\tat org.codehaus.jackson.map.deser.BaseNodeDeserializer.deserializeAny(JsonNodeDeserializer.java:216)\r\n\tat org.codehaus.jackson.map.deser.BaseNodeDeserializer.deserializeObject(JsonNodeDeserializer.java:187)\r\n\tat org.codehaus.jackson.map.deser.BaseNodeDeserializer.deserializeAny(JsonNodeDeserializer.java:213)\r\n\tat org.codehaus.jackson.map.deser.JsonNodeDeserializer.deserialize(JsonNodeDeserializer.java:56)\r\n\tat org.codehaus.jackson.map.deser.JsonNodeDeserializer.deserialize(JsonNodeDeserializer.java:13)\r\n\tat

Any advise?

3 answers

2 votes
Joe Clark Atlassian Team Aug 12, 2012

Given that anything passed into the JSON-RPC API needs to conform to the JSON spec, it's probably not possible to pass in a byte array value to Confluence via the JSON-RPC API.

I've raised a bug report for this problem - https://jira.atlassian.com/browse/CONF-26304

In the meantime, you could try using XML-RPC to add the attachment, which will accept the byte array value as a Base64-encoded String.

The XML-RPC is not also working due to the old implementation of axis as some of confluence methods are overloaded and the new version of axis does not allow overloading so I'm failing to use it as well.

It looks likey your string has some non-printable char with code 0 that not allowed by jackson. Check column 178 try write it again from keyboard without any copy-paste

I don't see any improper charachter at all. Have you ever used this method successfuly? Can you please give me a code example?

How do u sent the attachments? I convert it to binary.

I didn't used that method at all, just suggested. It can be binary object problem too if it use some non-printable characters in encoded form. What encoding do you use for binary object serialisation?

Convenient method for that is http://en.wikipedia.org/wiki/Base64

FWIW I've got a JSON-RPC addAttachment call working from the browser via ajax. You have to Base64 encode the binary content ( even if it is just text ). We're using the native btoa() method provided by modern browsers. If you need legacy IE support you'll have to roll your own encoder. Also be careful that if your text includes unicode you'll need to do some additional swizzling before you Base64 encode. Something like this:

window.btoa(unescape(encodeURIComponent( str )));

See here for more details on why you need to do this:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding#The_.22Unicode_Problem.22

I've tried doing this with a random JPG file using the FileReader.readAsDataURL method but I get an "unable.to.parse.method.arguments" error. Did you encounter this? And if so, how did you work around it?

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

116 views 0 10
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