Add dynamic value in url retrofit

I have this below URL


In the interface I have as

suspend fun fileUploadPathCheque(@Path("fileName") name: String): Response<String>

I want to replace the file name with some value

I am calling the function as


I get the following exception

ava.lang.IllegalArgumentException: URL query string "bucketName=files&key=payment-receipt/{fileName}&httpVerb=2&contentType=image/jpeg" must not have replace block. For dynamic query parameters use @Query.

What shoudl be correct way of doing this?

>Solution :

The exception is self-explanatory, You need to use a query parameter for key. Something like

suspend fun fileUploadPathCheque(@Query("key") name: String): Response<String>`

and then call it appending payment-receipt/ to your passing parameter:

Api.fileUploadPathCheque("payment-receipt/" + UUID.randomUUID().toString().plus(".jpg"))

This should work for you.

Leave a Reply