0

I'm using the code posted below for uploading image files to the server. Now I want to get the uploaded file size in order to show progress with uploaded file percentage. So I'm in need to get uploading file size i.e bytesWritten size inside executeInternal() method. This is the code:

 public Response createTooteet(int type, String id, HttpEntity entity, String filePath) {
        HttpPost httpPost = new HttpPost(getUrlByType(type));
        addHeader(httpPost, id);
        httpPost.addHeader(entity.getContentType());
        httpPost.setEntity(entity);
        return execute(httpPost, entity, filePath);
    }

     private Response execute(HttpPost httpPost, HttpEntity entity, String filePath) {
        return executeInternal(0, httpPost, entity, filePath);
    }

      private Response executeInternal(int retry, HttpPost httpPost, HttpEntity entity, String filePath) {

        String content = null;
        int responseCode = -1;

        try {
            if (Constants.DEBUG) {
                try{
                    ByteArrayOutputStream bout = new ByteArrayOutputStream();
                    entity.writeTo(bout);
//                    Log.e(TAG, "url:" + httpPost.getRequestLine().toString());
                }catch (Exception e){
//                    Log.d(TAG,"out of memory exception________________"+e.getMessage());
                    e.printStackTrace();
                }

            }

            HttpResponse response = mHttpClient.execute(httpPost);
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    response.getEntity().getContent(), "UTF-8"));
            responseCode = response.getStatusLine().getStatusCode();
            StringBuilder s = new StringBuilder();
            String sResponse;
            while ((sResponse = reader.readLine()) != null) {
                s = s.append(sResponse);
            }
            content = s.toString();

            if (Constants.DEBUG) {
                //Log.e(TAG, "response:" + responseCode + "-" + content);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        Response response = new Response(responseCode, content);
        if (!response.isSuccess() && response.getStatusCode() == HttpStatus.SC_UNAUTHORIZED && retry == 0) {
            if (login()) {
                httpPost.setHeader(ParamNames.USER_TOKEN, mUserPreference.getUserToken());
                return executeInternal(retry + 1, httpPost, entity, filePath);
            } else {
                return new Response(0, StatusCodes.LoginHandler.getErrorMessage(mContext, 0));
            }
        }

//        Log.d("Server request-----","response" + response.getContent() + " suc" + response.isSuccess());

        return response;
    } 

How would I go about getting the value of how much of a current file in progress is already uploaded?

Magisch
  • 7,312
  • 9
  • 36
  • 52
Sangeetha
  • 496
  • 1
  • 7
  • 25
  • This link may help you. http://stackoverflow.com/questions/10976488/android-progress-bar-to-upload-data-to-the-server –  Aug 02 '16 at 09:29
  • This link may help you also. http://stackoverflow.com/questions/2105364/android-i-want-to-show-file-upload-progress-to-the-user –  Aug 02 '16 at 09:31
  • 1
    Hi Please refer this link its solve my problem – Sangeetha Aug 08 '16 at 13:00

0 Answers0