Let me share some of my code which i have implemented to send image file in the request.
Below is my function of api request:
@Multipart
@POST("api/order/order_create")
fun createOrder(
    @Header("Authorization") authorization: String?,
    @Part("category_id") categoryId: RequestBody?,
    @Part("size") size: RequestBody?,
    @Part("narration") narration: RequestBody?,
    @Part("ref_picture") file: RequestBody?
): Call<OrderCreateResponse>
Below is the code where i am calling the api by sending the necessary parameters:
var fbody = RequestBody.create(MediaType.parse("image/*"), imageFile)
var size = RequestBody.create(MediaType.parse("text/plain"), et_custom_order_size.text.toString())
var catId = RequestBody.create(MediaType.parse("text/plain"), selectedID.toString())
var narration = RequestBody.create(MediaType.parse("text/plain"),et_custom_order_narration.text.toString())
val orderCreateAPI = apiService!!.createOrder(complexPreferences?.getPref("token", null), catId,size,narration,fbody)
Here imageFile is fetched by the below way,
imageFile = File(Global.getRealPathFromURI(activity!!, imageUri!!))
Using below function to get the real path,
fun getRealPathFromURI(context: Context, contentUri: Uri): String {
        var cursor: Cursor? = null
        try {
            val proj = arrayOf(MediaStore.Images.Media.DATA)
            cursor = context.contentResolver.query(contentUri, proj, null, null, null)
            val column_index = cursor!!.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)
            cursor.moveToFirst()
            return cursor.getString(column_index)
        } catch (e: Exception) {
            Log.e(TAG, "getRealPathFromURI Exception : " + e.toString())
            return ""
        } finally {
            if (cursor != null) {
                cursor.close()
            }
        }
    }
By sending image in the above way, i am not able to send it! Please guide me with the same. Thanks in advance.
 
     
     
    