Skip to content
This repository has been archived by the owner on Nov 8, 2018. It is now read-only.

Multipart upload image along with other text fileds #5

Closed
nowfalsalahudeen opened this issue Feb 23, 2018 · 3 comments
Closed

Multipart upload image along with other text fileds #5

nowfalsalahudeen opened this issue Feb 23, 2018 · 3 comments

Comments

@nowfalsalahudeen
Copy link

how can i upload a image file along with other text strings

@post("/user/profile/update")
fun updateProfile(@Header("Authorization") headerAuth: String,
@Body @multipart(name = "image", mimeType = "image/*") file: Uri,
@part("name")name: String,
@part("email")email: String): Observable

this code gives error

@jaychang0917
Copy link
Owner

What error you get? You should use RequestBody instead of String since only Uri type is handled by this library.

E.g.

fun updateProfile(@Header("Authorization") headerAuth: String,
@Body @Multipart(name = "image", mimeType = "image/*") file: Uri,
@Part("name")name: RequestBody,
@Part("email")email: RequestBody): Observable

@nowfalsalahudeen
Copy link
Author

thanx will check it and inform back to you

@nowfalsalahudeen
Copy link
Author

this is i got..

java.lang.IllegalArgumentException: @part parameters can only be used with multipart encoding. (parameter #3)
for method EkalawyaApi.updateProfile
at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:752)
at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:743)
at retrofit2.ServiceMethod$Builder.parameterError(ServiceMethod.java:761)
at retrofit2.ServiceMethod$Builder.parseParameterAnnotation(ServiceMethod.java:592)
at retrofit2.ServiceMethod$Builder.parseParameter(ServiceMethod.java:336)
at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:204)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:170)
at retrofit2.Retrofit$1.invoke(Retrofit.java:147)
at java.lang.reflect.Proxy.invoke(Proxy.java:913)
at $Proxy0.updateProfile(Unknown Source)

code i have used.
@post("/user/profile/update")
fun updateProfile(@Header("Authorization") headerAuth: String,
@Body @multipart(name = "image", mimeType = "image/*") file: Uri,
@part("name")name: RequestBody,
@part("email")email: RequestBody): Observable

Api.create().updateProfile("UserToken",
pickedImage, //Uri
RequestBody.create(MediaType.parse("text/plain"), name.text.toString()),
RequestBody.create(MediaType.parse("text/plain"), email.text.toString())).observe(
onStart = {

            },
            onEnd = {

            },
            onError = {
                println(it.message)
            },
            onSuccess = {
                println(it)
            }
    )

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants