0

i am able to upload image using postman :

enter image description here

but when i tried using multi-part entity using retrofit i am not able to upload that it tell file is not find in server below is my code:

public void visitrecord_existingtask(int userId, String companyId, String taskId, String actionTaken, String timeSpend, double lat, double longi, ArrayList<String> filePaths) {
        MultipartBody.Builder builder = new MultipartBody.Builder();
        builder.setType(MultipartBody.FORM);
        builder.addFormDataPart("userid", String.valueOf(userId));
        builder.addFormDataPart("companyid", companyId);
        builder.addFormDataPart("taskid", taskId);
        builder.addFormDataPart("task_actiontaken", actionTaken);
        builder.addFormDataPart("timespent", timeSpend);
        builder.addFormDataPart("latitude", String.valueOf(lat));
        builder.addFormDataPart("longitude", String.valueOf(longi));
        for (int i = 0; i < filePaths.size(); i++) {
            File file = new File(filePaths.get(i));
            builder.addFormDataPart("files", file.getName(), RequestBody.create(MediaType.parse("multipart/form-data"), file));
        }
        MultipartBody requestBody = builder.build();
        Call<VisitrecordExistingtask> call = webAPIInterface.visitrecordExistingtask(requestBody);
        call.enqueue(new Callback<VisitrecordExistingtask>() {
            @Override
            public void onResponse(Call<VisitrecordExistingtask> call, Response<VisitrecordExistingtask> response) {
                visitrecordlistner.showLoginResult(response.code(), response.body());
            }

            @Override
            public void onFailure(Call<VisitrecordExistingtask> call, Throwable t) {
                visitrecordlistner.showError(t);
            }
        });

    }

this is my code which i am using file upload to server i have to send soem parameter plus image file to server but its not able to find image in server can any one please suggest me what i am doing wrong .

9
  • this ans will help you stackoverflow.com/questions/39866676/… Mar 31, 2018 at 12:59
  • do need to install one image..or multiple images?@Joan Mar 31, 2018 at 13:09
  • @ AL Tegani one image only i have to upload not multiple
    – Joan
    Mar 31, 2018 at 14:08
  • @Joan i will modifiy your code to upload one image..but what is the purpose of this ArrayList<String> filePaths why list this against your needs?? Mar 31, 2018 at 14:22
  • we have to create some multiple file upload it i want to use it as reusable component
    – Joan
    Mar 31, 2018 at 14:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.