Created
September 6, 2018 07:21
-
-
Save Audhil/d3a4ebc96fd980f6e6c0f46979d2402e to your computer and use it in GitHub Desktop.
multi-part request (uploading an Image) with Retrofit2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface AppAPIs { | |
@Multipart | |
@POST(APIEndPoints.UPLOAD_PHOTO) | |
fun uploadTempProfilePic( | |
@Query(APIEndPoints.ID) | |
tempId: String, | |
@Part | |
image: MultipartBody.Part | |
): Flowable<PhotoUploadResponse> | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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