2

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?

pRaNaY
  • 24,642
  • 24
  • 96
  • 146
  • 1
    Have a look here [http://stackoverflow.com/a/37571549/4199996](http://stackoverflow.com/a/37571549/4199996) and compile 2.0.2 instead – Tristan Richard Jun 07 '16 at 06:43

3 Answers3

5

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 .

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
1

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);
    }
    }
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
SaravInfern
  • 3,338
  • 1
  • 20
  • 44
0

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
Teodor Hirs
  • 449
  • 5
  • 8