okhttp发布的最大尺寸

时间:2018-10-11 14:06:01

标签: android post okhttp

我的应用中存在多篇文章,因此我遇到了问题。 它只适用于许多小文件,但是2 Mo文件以外的地方出了问题,它们无法到达目标服务器。 服务器的配置似乎还可以,并且下载过程是无限的,非常完美。 我一直在看看Android中是否有配置,但是什么也没出现... 这是我的asynctask代码

private class fetchtask2 extends AsyncTask<String, Void, String>{
    protected String doInBackground(String... strings) {
        OkHttpClient client2 = new OkHttpClient();
                /*.Builder()
                .writeTimeout(10, TimeUnit.SECONDS)
                .build();*/
        MultipartBody.Builder formBody2 = new MultipartBody.Builder()
                .setType(MultipartBody.FORM);


        for(int j=0;j<stringArrayList_upload.size();j++){
            final String[]split = stringArrayList_upload.get(j).split(";");
            imei = split[4].toString();
            dir = split[1].toString();
            //image = split[2].toString();

            filename = split[2].toString();
            image = Environment.getExternalStorageDirectory() + File.separator + "SmartCollecte" + File.separator + dir+File.separator+filename;
            newfilename = filename.replace(".","#");
            sha = split[3].toString();
            File file = new File(image);
            if(!file.exists()) {
                // Toast.makeText(getApplicationContext(), "pas de fichier", Toast.LENGTH_SHORT).show();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(AboutActivity.this, "le fichier : " +image+" n'existe pas",Toast.LENGTH_SHORT).show();
                    }
                });
            }
            formBody2.addFormDataPart("imei",imei)
                    .addFormDataPart("dir",dir)
                    .addFormDataPart("sha",sha)
                    .addFormDataPart(String.valueOf(j)+"£"+dir, image, RequestBody.create((MediaType.parse("text/csv")), file));





            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                   // Toast.makeText(MainActivity_old.this, dir.toString(),Toast.LENGTH_SHORT).show();
                }
            });
            //Toast.makeText(getApplicationContext(),split[0].toString(),Toast.LENGTH_SHORT).show();

        }
        RequestBody tesformBody = formBody2.build();

        Request request2 = new Request.Builder()
                .url("my_url_upload")
                .post(tesformBody)
                .build();
        try{
            Response reponse2 = client2.newCall(request2).execute();
            if(!reponse2.isSuccessful())throw new IOException("Unexpected code"+reponse2);

        }catch(IOException e){
            e.printStackTrace();
        }
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                // Toast.makeText(MainActivity_old.this, dir.toString(),Toast.LENGTH_SHORT).show();

            }
        });


        return null;
    }
    @Override
    protected void onCancelled(){
        Log.d(TAG,"l'upload a été annulé");
    }
}

0 个答案:

没有答案
相关问题