Skip to content

Instantly share code, notes, and snippets.

@Audhil
Created September 6, 2018 07:21
Show Gist options
  • Save Audhil/d3a4ebc96fd980f6e6c0f46979d2402e to your computer and use it in GitHub Desktop.
Save Audhil/d3a4ebc96fd980f6e6c0f46979d2402e to your computer and use it in GitHub Desktop.
multi-part request (uploading an Image) with Retrofit2
interface AppAPIs {
@Multipart
@POST(APIEndPoints.UPLOAD_PHOTO)
fun uploadTempProfilePic(
@Query(APIEndPoints.ID)
tempId: String,
@Part
image: MultipartBody.Part
): Flowable<PhotoUploadResponse>
}
fun uploadAnImage() {
val requestFile = RequestBody.create(MediaType.parse("image/*"), imageBytes)
val multiPartBody = MultipartBody.Part.createFormData("content", "profile.jpg", requestFile)
viewModel.uploadTempProfilePic(
tempId,
multiPartBody
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment