اذهب إلى المحتوى
  • 0

progress bar volley multipart request android studio

Drive Man

السؤال

  private void uploadvideo(final String pdfname, Uri pdffile){
        InputStream iStream = null;

        try {

            iStream = getContentResolver().openInputStream(pdffile);
            final byte[] inputData = getBytes(iStream);
            String oo=String.valueOf(inputData);
            Log.d("finalert",oo);
            VolleyMultipartRequest volleyMultipartRequest = new VolleyMultipartRequest(Request.Method.POST, URLphp,
                    new Response.Listener<NetworkResponse>() {
                        @Override
                        public void onResponse(NetworkResponse response) {
                        progressDialog.dismiss();
                            Log.d("ressssssoo",new String(response.data));
                            Toast.makeText(uploadved.this,new String(response.data), Toast.LENGTH_SHORT).show();
                            String tt=new String(response.data);
                            if (tt=="منشورك موجود الان بالعامة شكرا لتفاعلك معنا"){
                                //startActivity(new Intent(uploadved.this,watchervedio.class));
                                Toast.makeText(uploadved.this, "yes", Toast.LENGTH_SHORT).show();
                            }
                            rQueue.getCache().clear();
                            try {
                                JSONObject jsonObject = new JSONObject(new String(response.data));
                                //Toast.makeText(uploadved.this, response.toString(), Toast.LENGTH_SHORT).show();


                            } catch (JSONException e) {
                                Toast.makeText(uploadved.this, "", Toast.LENGTH_SHORT).show();
                            }
                        }
                    },
                    new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
                        }
                    }) {

                /*
                 * If you want to add more parameters with the image
                 * you can do it here
                 * here we have only one parameter with the image
                 * which is tags
                 * */
                @Override
                protected Map<String,String> getParams() throws AuthFailureError {
                    Map<String,String> params = new HashMap<>();
                    params.put("***", shall.getInstance(uploadved.this).getuserShow());
                    params.put("****", shall.getInstance(uploadved.this).getimage());
                    params.put("***", shall.getInstance(uploadved.this).getid());
                    params.put("***",enwanvido);
                    return params;
                }

                /*
                 *pass files using below method
                 * */
                @Override
                protected Map<String, DataPart> getByteData() {
                    Map<String, DataPart> params = new HashMap<>();
                    params.put("***", new DataPart(pdfname ,inputData));
                    Log.d("testerget work","workingpartdata");
                    return params;
                }
            };



            volleyMultipartRequest.setRetryPolicy(new DefaultRetryPolicy(
                    0,
                    DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                    DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
            rQueue = Volley.newRequestQueue(uploadved.this);
            rQueue.add(volleyMultipartRequest);



        } catch (FileNotFoundException e) {
            Toast.makeText(this, "لم يتم التعرف على الملف ", Toast.LENGTH_SHORT).show();
        } catch (IOException e) {
            Toast.makeText(this, "هناك مشكلة بالانترنت  ", Toast.LENGTH_SHORT).show();
        }


    }

    public byte[] getBytes(InputStream inputStream) throws IOException {
        ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
        int bufferSize = 1024;
        byte[] buffer = new byte[bufferSize];
        int len = 0;
        int fileSize = inputStream.read();

        long uploadedBytes = 0;
        while ((len = inputStream.read(buffer)) != -1) {
            byteBuffer.write(buffer, 0, len);




        }

        return byteBuffer.toByteArray();
    }

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...