Unable to upload video using Retrofit, possible fix?
<p>I am trying to upload video to server using <code>Retrofit</code> as multi part form data , And I am using <code>Retrofit</code> version: 2.02</p>

<pre><code>compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
</code></pre>

<p>This is the code to the API client class:</p>

<h3> ApiClient.java </h3>

<pre><code>    public class ApiClient {

    public static final String BASE_URL = "https://api.sproutvideo.com";
    private static Retrofit retrofit = null;


    public static Retrofit getClient() {
        if (retrofit==null) {
            retrofit = new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
        }
        return retrofit;
    }
}
</code></pre>

<p>This is the code to API interface:</p>

<h3> ApiInterface.java </h3>

<pre><code>    public interface ApiInterface {
    @Multipart
    @POST("/v1/videos")
    Call&lt;SproutReply&gt; pushVideo (@Header("SproutVideo-Api-Key") String key, @Part("file\"; filename=\"pp.mp4") RequestBody file);
}
</code></pre>

<p>And my requirement is to upload the video picked using <code>Intent.ACTION_PICK</code>. </p>

<p>And this is how I invoke the API:</p>

<pre><code> private void makeRequest(Uri uri)
{


   try {
       String path = uri.toString();
       Log.e("PATH", path);
       URI ss = new URI(uri.toString());
       file = new File(ss);

   }
   catch (Exception e){}


    RequestBody video = RequestBody.create(MediaType.parse("video/mp4"),file);
    //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    ApiInterface apiService =
            ApiClient.getClient().create(ApiInterface.class);

    Call&lt;SproutReply&gt; call = apiService.pushVideo(KEY,video);
    call.enqueue(new Callback&lt;SproutReply&gt;()
    {
        @Override
        public void onResponse(Call&lt;SproutReply&gt; call, Response&lt;SproutReply&gt; response)
        {
            try
            {
                Log.e("TAG",""+response.body().toString());




            }
            catch (Exception e)
            {
                Toast.makeText(getActivity(), "Check data connection", Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onFailure(Call&lt;SproutReply&gt; call, Throwable t)
        {
            // Log error here since request failed
            Log.e("FAILURE", t.toString());
        }
    });


}
</code></pre>

<p>The call results in a <code>NullPointerException</code> as <code>content == null</code> at this line:</p>

<pre><code>RequestBody video = RequestBody.create(MediaType.parse("video/mp4"),file);
</code></pre>

<p>However in this line when I log the Uri( <code>Log.e("PATH", path);</code> ) as String I obtain the value as :</p>

<blockquote>
  <p>content://com.android.providers.media.documents/document/video%3A75406</p>
</blockquote>

<p>And using this Uri I am able to play video in <code>VideoView</code> as well, however in Retrofit it seems to crash, what is possibly causing this and how to fix?</p>

<p>Here is the logcat as well:</p>

<pre><code>java.lang.NullPointerException: content == null
                                                             at okhttp3.RequestBody.create(RequestBody.java:103)
                                                             at com.example.demovid.UploadFragment.makeRequest(UploadFragment.java:91)
                                                             at com.example.demovid.UploadFragment.onEvent(UploadFragment.java:133)
                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                             at org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:485)
                                                             at org.greenrobot.eventbus.EventBus.postToSubscription(EventBus.java:416)
                                                             at org.greenrobot.eventbus.EventBus.postSingleEventForEventType(EventBus.java:397)
                                                             at org.greenrobot.eventbus.EventBus.postSingleEvent(EventBus.java:370)
                                                             at org.greenrobot.eventbus.EventBus.post(EventBus.java:251)
                                                             at com.example.demovid.MainActivity.onActivityResult(MainActivity.java:67)
                                                             at android.app.Activity.dispatchActivityResult(Activity.java:6456)
                                                             at android.app.ActivityThread.deliverResults(ActivityThread.java:3729)
                                                             at android.app.ActivityThread.handleSendResult(ActivityThread.java:3776)
                                                             at android.app.ActivityThread.-wrap16(ActivityThread.java)
                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412)
                                                             at android.os.Handler.dispatchMessage(Handler.java:102)
                                                             at android.os.Looper.loop(Looper.java:148)
                                                             at android.app.ActivityThread.main(ActivityThread.java:5461)
                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
</code></pre>