first, of all i tried to follow this question but it doesn't works.
I have to call an API and send an image and a user name in the body, i do have called the APIs before using the retrofit but i have no idea how to send an image now.
here is my code as of now
private fun uploadProfileToDashboard(path: String) {
var aes = Utils.getPref(
requireContext(),
Constants.ENCRYPTION_AES,
"x"
)!!
var iv = Utils.getPref(
requireContext(),
Constants.ENCRYPTION_IV,
"x"
)!!
val file: File = File(path)
val fbody = RequestBody.create(
"image/*".toMediaTypeOrNull(),
file
)
profileViewModel.updateProfilePicInDashboard(
mapOf(
"object_id" to Utils.getPref(
requireContext(),
Constants.ENCRYPTION_OBJ_ID,
"x"
)!!,
"db_name" to Utils.getPref(
requireContext(),
Constants.PROVIDER_NAME,
"x"
)!!
),
AESEncryption(
aes,
iv
).encrypt(profile.dashboardUserName)!!,
fbody
)
}
fun updateProfilePicInDashboard(
headerParams: Map<String, String>,
user_id: String,
image: RequestBody
) {
val call = RetrofitClient.updateProfilePicInDashboard.updateProfilePic(headerParams , user_id , image)
call.enqueue(object : Callback<UserProfilePicResponceModal> {
override fun onResponse(
call: Call<UserProfilePicResponceModal>,
response: Response<UserProfilePicResponceModal>
) {
Log.i("here22" , response.body().toString())
}
override fun onFailure(call: Call<UserProfilePicResponceModal>, t: Throwable) {
Log.i("here22" , t.message.toString())
}
})
}
@Multipart
@FormUrlEncoded
@POST("/index.php/Profile/editProfile")
fun updateProfilePic(
@HeaderMap headers: Map<String, String>,
@Part("user_id") userId: String,
@Part("file\"; filename=\"pp.png\" ") userfile: RequestBody
) : Call<UserProfilePicResponceModal>
But this does work, it fire an error -> Failure delivering result ResultInfo{who=null, request=67940, result=-1, data=Intent