0

I am facing problem when sending file through retrofit2. But the web api working fine on Postman hit. Error Stated in responsebody:

Response{protocol=http/1.1, code=404, message=Not Found, url=MYURL}

Retrofit2 endpoint:

@Multipart
@POST("FileStorage/UploadDataFile")
Call<ResponseBody> uploadFile(@Part MultipartBody.Part file,@Part("file") RequestBody name);

Updated code:

// Uploading File
    private void uploadFile() {

        File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) +
                File.separator + "dbBackup"+
                File.separator +"gps_db_4522_190122114644.sqlite");
          //File file = new File(mediaPath);
        Retrofit retrofit = RetrofitSingleton.getInstance(getActivity().getBaseContext());
        final CommonApiInterface commonApiInterface = retrofit.create(CommonApiInterface.class);

          RequestBody requestBody = RequestBody.create(MediaType.parse("*/*"), file);
        MultipartBody.Part fileToUpload = MultipartBody.Part.createFormData("file", file.getName(), requestBody);
        RequestBody filename = RequestBody.create(MediaType.parse("text/plain"), file.getName());

        commonApiInterface.uploadFile(fileToUpload,filename).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                if(response.isSuccessful()) {
                    Toast.makeText(getActivity(), "Saved Successfully...", Toast.LENGTH_SHORT).show();
                }

            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                Toast.makeText(getActivity(), "Save Fail: " + t, Toast.LENGTH_SHORT).show();
            }
        });
    }
halfer
  • 19,824
  • 17
  • 99
  • 186
Majedur
  • 3,074
  • 1
  • 30
  • 43

1 Answers1

0

Finally i found my problem. The endpoint was incorrect

@Multipart
@POST("FileStorage/UploadDataFile")
Call<ResponseBody> uploadFile(@Part MultipartBody.Part file,@Part("file") RequestBody name);

correct endpoint is @POST("FileProcessing/UploadDataFile")

Majedur
  • 3,074
  • 1
  • 30
  • 43