如何计算在改造中使用multipart发送了多少文件?

时间:2017-09-14 10:48:43

标签: android retrofit multipart

我正在尝试创建一个应用程序,其中包括使用Retrofit 2上传多部分图像,我还无法弄清楚如何计算已发送的文件数量?

我使用this answer作为计算我上传了多少百分比的方法,但它并没有真正计算我上传了多少个文件。

这就是我如何使用改造来启动我的请求



 HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();

        uploadService = new Retrofit.Builder().baseUrl("http://someserver.com/").client(client).build().create(UploadService.class);

MultipartBody.Part[] spajImageParts = new MultipartBody.Part[mCompressedFileFormate.size()];

        for (int index = 0; index < mCompressedFileFormate.size(); index++) {
            File f = new File(mCompressedFileFormate.get(index).getPath());
            ProgressRequestBody fileBody = new ProgressRequestBody(f, this);

            spajImageParts[index] = MultipartBody.Part.createFormData("upload", no_spa + f.getName(), fileBody);
        }

    RequestBody name = RequestBody.create(MediaType.parse("text/plain"), "upload_test");
            retrofit2.Call<okhttp3.ResponseBody> req = uploadService.postImage(spajImageParts, name);
            req.enqueue(new Callback<ResponseBody>() {
&#13;
&#13;
&#13;

0 个答案:

没有答案