Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,364,733
Community Members
 
Community Events
168
Community Groups

500 code while adding attachemnt via REST API (Kotlin)

Edited

Hi,

 

I'm trying to upload an image to a Confluence page via REST API. I'm stuck on getting 500 response code and not enough meaningful message what I'm doing wrong.

 

Here is the peace of code I'm using for that, in Kotlin, Retrofit2 (I'm newbie):

interface ConfluenceService {
@Multipart
@Headers(
"X-Atlassian-Token: no-check",
"Content-Type: multipart/form-data"
)
@PUT("content/{pageId}/child/attachment")
suspend fun sendAttachments(
@Path("pageId") pageId: String,
@Part file: MultipartBody.Part,
@Header("Authorization") authorization: String
): Response<String>
}
suspend fun sendAttachments(pageId: String) : Boolean {
val file = File(pathToSomeFile)
val filePart: MultipartBody.Part = MultipartBody.Part.createFormData(
"file",
file.name,
RequestBody.create(MediaType.parse("image/*"), file.readBytes())
)

val service = RetrofitClient().create(baseUrl).create(ConfluenceService::class.java)

val response = service.sendAttachments(pageId, filePart,"Basic $credentials")

return response.isSuccessful
}

 Any suggestions? 

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS

Atlassian Community Events