To_java_bytes - byte arrays

I need to open a file, read the contents, and convert to a byte array.

I have tried:

read the file from disk that will be attached to the page

f =“file.jpg”, “r”)
contents =
java_bytes = contents.to_java_bytes

puts “java_bytes is of type #{java_bytes.class}”

gives: “java_bytes is of type #Class:01x41c977” - not right?

I now need to pass java_bytes, and other args, to the method below

Confluence API]

addAttachment(String token, long contentId,

byte[] attachmentData)

newattachment = service.addAttachment(@sid, ‘40932323’, attachment,

However, the service.addAttachment line gives the error:
“… no addAttachment with arguments matching [class java.lang.String,
class java.lang.String, class
com.sun.dse.wikis.remote.stub.RemoteAttachment, class [B] on object
JavaUtilities (NameError) …”

Error looks as if it’s with the 4th arg - the byte[]. I’ve used
to_java_bytes to convert the file to a binary array, but it doesn’t look

Any thoughts?



Looks like you’re passing contentId as a String, when it’s expecting a


exactly. sigh …

Thank you.