Last active
May 4, 2017 20:27
-
-
Save danielgomezrico/4586a7656acfb779bb489538f1310876 to your computer and use it in GitHub Desktop.
Android / Retrofit 2 - Upload file
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 uploadFile(user: User, avatarPath: String, mimeType: String): Observable<Answer<Any>> { | |
val avatarFile = File(avatarPath) | |
val requestFile = RequestBody.create(MediaType.parse(mimeType.toLowerCase()), avatarFile) | |
val body = MultipartBody.Part.createFormData("file", avatarFile.name, requestFile) | |
return service.uploadFile(user.id, body) // Service is an instance created by retrofit with Service.kt | |
} |
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
@Multipart | |
@PUT("/api/files") | |
fun uploadFile(@Part file: MultipartBody.Part): Observable<Response<Any>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment