0

I'm trying to upload a file with refrofit and php, it works but it is going to onFailure do not know why... If I print stacktrace it says.. com.google.gson.JsonIOException: JSON document was not fully consumed.

With this I upload the file...

RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), archivo);

                MultipartBody.Part multipartBody = MultipartBody.Part.createFormData("fichero",archivo.getName(),requestFile);

                call.enqueue(new Callback<Usuario>() {
                    @Override
                    public void onResponse(Call<Usuario> call, Response<Usuario> response) {


                        Toast.makeText(PrincipalActivity.this, response.body().getResponse(), Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onFailure(Call<Usuario> call, Throwable t) {

                        Toast.makeText(PrincipalActivity.this, "Error de Conexión", Toast.LENGTH_SHORT).show();
                         t.printStackTrace();

                        int lala=0;

                    }
                });




public interface MetodosApi {


    @Multipart
    @POST("subir.php")
    Call<Usuario> subirArchivo(@Part MultipartBody.Part file);

}



public static Retrofit obtieneRetrofit() {

        if(retrofit==null) {

            Gson gson = new GsonBuilder()
                    .setLenient()
                    .create();

            OkHttpClient okHttpClient = new OkHttpClient();

            retrofit= new Retrofit.Builder().baseUrl(url).client(okHttpClient).addConverterFactory(GsonConverterFactory.create(gson))
                    .build();
        }

        return retrofit;

    }

Do not know where is the problem...

eloymm
  • 1
  • 2

0 Answers0