pRaNaY
pRaNaY

Reputation: 25312

Value missing though required retrofit 2.0

I am using Retrofit 2.0 to create retrofit service for uploading file on server.

I am refering https://futurestud.io/blog/retrofit-2-how-to-upload-files-to-server

Below is my FileUploadService code:

interface TripHistoryFileUploadService {
@Multipart
@POST("trip/trip-history")
Call<ResponseBody> upload(@Part("json_file") RequestBody description,
                          @Part MultipartBody.Part file);

}

I am using below retrofit version:

 compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'

But I am getting error Value missing though required like below:

enter image description here

Can any one face same problem or any one have solution for the same?

Upvotes: 2

Views: 1522

Answers (3)

Teodor Hirs
Teodor Hirs

Reputation: 489

I was in similar situation and it turns out to be trivial thing - I've imported Part from first version of retrofit instead of second. So at least you can do is tu check if you have

import retrofit.http.Part; -> requires value

instead of

import retrofit2.http.Part; -> doesn't required value

Upvotes: 0

SaravInfern
SaravInfern

Reputation: 3388

You are missing part name to the second argument

interface TripHistoryFileUploadService {
    @Multipart
    @POST("trip/trip-history")
    Call<ResponseBody> upload(@Part("json_file") RequestBody description,
                          @Part("part_name_missing here") MultipartBody.Part file);
    }
    }

Upvotes: 1

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75778

beta Version is An early version of a program or application that contains most of the major features, but is not yet complete.

You should use Stable

compile 'com.squareup.retrofit2:retrofit:2.0.2' //A type-safe HTTP client

Then Clean -Rebuild-Sync Your IDE .Hope this helps you .

Upvotes: 5

Related Questions