【问题标题】:How to upload Multiple Images using Array List in android如何在android中使用数组列表上传多个图像
【发布时间】:2021-06-17 15:57:56
【问题描述】:

我尝试了很多解决方案,但没有一次适合我。

我正在以这种方式接收图像数据:

ArrayList<String> filePaths = data.getStringArrayListExtra(Pix.IMAGE_RESULTS);

并使用多部分上传图片

MultipartBody requestBody = builder.build();
    Call<Status_Response> call = taskMetServer.uploadMultiplePics(requestBody.parts());
    call.enqueue(new Callback<Status_Response>() {
        @Override
        public void onResponse(Call<Status_Response> call, Response<Status_Response> response) {

            if(response.isSuccessful()){

                Status_Response status_response = response.body();

                assert status_response != null;
                String msg = status_response.getStatus();

                Log.d("myMessage", "\n\nStatus: "+msg);

                progressBar.setVisibility(View.GONE);
                Toast.makeText(getContext(), "Success " + response.message()+response.code(), Toast.LENGTH_LONG).show();
                
            }
        }

        @Override
        public void onFailure(Call<Status_Response> call, Throwable t) {
            progressBar.setVisibility(View.GONE);
            Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_SHORT).show();

        }
    });
}

我的界面是:

@POST("test/store")
Call<Status_Response> uploadMultiplePics(
        @Body List<MultipartBody.Part> images
);

但仍然收到 null 作为响应,而不是 true 或 false:

2021-03-20 17:36:38.076 10582-10582/com.example.ourproductapp D/myMessage: [/storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20210320-WA0082.jpeg]

2021-03-20 17:36:38.732 10582-10582/com.example.ourproductapp D/myMessage: Status: null

提前致谢

【问题讨论】:

    标签: java android api android-studio retrofit2


    【解决方案1】:

    检查您的后端服务,您的服务器是否正在获取文件。 或者你可以使用https://github.com/gotev/android-upload-service

    【讨论】:

      猜你喜欢
      • 2018-11-09
      • 2017-09-10
      • 2019-12-19
      • 1970-01-01
      • 2018-10-14
      • 2016-09-18
      • 2019-06-21
      • 2022-10-19
      • 2018-09-11
      相关资源
      最近更新 更多