如何在 android 中使用数组列表上传多张图片

How to upload Multiple Images using Array List in android

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

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

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

并使用 multipart 上传图片

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

提前致谢

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