Skip to content

Instantly share code, notes, and snippets.

@rezaiyan
Last active January 14, 2019 11:48
Show Gist options
  • Save rezaiyan/445d49379fffafe5dee4e2d02cf147bc to your computer and use it in GitHub Desktop.
Save rezaiyan/445d49379fffafe5dee4e2d02cf147bc to your computer and use it in GitHub Desktop.
Upload file with retrofit
// Activity
val file = File(path)
val requestFile = RequestBody.create(MediaType.parse(context.contentResolver.getType(data.data)), file)
val body = MultipartBody.Part.createFormData("avatar", file.name, requestFile)
presenter.uploadUserAvatar(body)
// Activity
// Endpoint.kt
@Multipart
@POST(Const.URL.USER_AVATAR_UPDATE)
fun uploadAvatar( @Part file: MultipartBody.Part): Observable<GetAvatarModel>
// Endpoint.kt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment