Retrofit - @Body parameters cannot be used with form or multi-part encoding. (parameter #1)

I want to send the local gallery image to api. I have added that images as a multipart typedfile and iam also sending some string data in the same api as a multipart typedstring.

So when i hit the api am getting this response.

@Body parameters cannot be used with form or multi-part encoding. (parameter #1)

My code:

                //Add the values into Multipart.
                MultipartTypedOutput multipartTypedOutput = new MultipartTypedOutput();
                //Add the ACCESS_TOKEN
                //MULTIPLEIMAGE
                multipartTypedOutput.addPart(Constants.LOGO_IMAGE, new TypedFile("image/*", new File("" + encodedByte)));
                //Add the ACCESS_TOKEN
                multipartTypedOutput.addPart(Constants.COMPANY_NAME, new TypedString(companyName));
                multipartTypedOutput.addPart(Constants.TAGS, new TypedString(projectTags));
                multipartTypedOutput.addPart(Constants.PROJECT_DESC, new TypedString(projectDesc));
                multipartTypedOutput.addPart(Constants.CATEGORY, new TypedString(categories));
                multipartTypedOutput.addPart(Constants.STYLE, new TypedString(launchStyle));
                multipartTypedOutput.addPart(Constants.COLOR_CODE, new TypedString(colorCode));
                multipartTypedOutput.addPart(Constants.CONTEST_PACK, new TypedString(contestPackage));
                multipartTypedOutput.addPart(Constants.PAYMENT_GATE, new TypedString(paymentGateway));
                multipartTypedOutput.addPart(Constants.USERID, new TypedString(userId));
                if (connectionDetector.isOnline()) {
                    apiManager.getApiService().launchApi(multipartTypedOutput, new LaunchCallback(LaunchStep4Fragment.this));
                } else {
                    Toast.makeText(getActivity(), getString(R.string.check_internet), Toast.LENGTH_SHORT).show();
                }

Interface method

/**
 * @param multipartTypedOutput
 * @param callback
 */
@FormUrlEncoded
@POST(Constants.STORE_CONTEST)
void launchApi(@Body MultipartTypedOutput multipartTypedOutput , Callback<LaunchResponse> callback);

In api side, they are getting everything as a string. So whether it depends on the parameter type or the code issue?

What should i change to get the result?

Please could someone explain me if i do anything wrong.

Upvotes: 1

Views: 13181

Answers (2)

Samir
Samir

Reputation: 6605

Try to remove @FormUrlEncoded I had the same error I removed @FormUrlEncoded and it worked

 //@FormUrlEncoded
    @POST("saveOgrYoklama")
    Call<YoklamaStatus> sendYoklamaList2(@Body Yoklama yoklama);

What I was trying to send to server

enter image description here

Upvotes: 0

yozzy
yozzy

Reputation: 344

Use Retrofit 2

@Headers({
        "Accept: application/json",
})
@Multipart
@POST("upload")
Call<ResponseBody> uploadImage(@Part("picture\"; filename=\"picture") RequestBody picture, @Part("company_name") RequestBody company_name);

Upvotes: 1

Related Questions