500 code while adding attachemnt via REST API (Kotlin)

Maciej Kopa September 11, 2022

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
AUG Leaders

Atlassian Community Events