0

I want to show uploading file size during web service. So I have used the following two links HttpClient Post with progress and MultipartEntityBuilder, gradle-hockeyapp-plugin where i found the ProgressHttpEntityWrapper.java class. Using this class I have found the uploading file size. Using the below method

 public String getFileSize(long size) {
        if (size <= 0)
            return "0";
        final String[] units = new String[] { mContext.getResources().getString(R.string.bytes), mContext.getResources().getString(R.string.kilo_bytes), mContext.getResources().getString(R.string.mega_bytes), mContext.getResources().getString(R.string.giga_bytes), mContext.getResources().getString(R.string.tera_bytes) };
        int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
        return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
    }

but it gives wrong file size compare than the original file size. Both actual and uploading total file sizes vary.

For example, my actual file size 297.1 KB but it show the total file size is 365.5 KB. Why the actual file size and uploaing total file size gets vary. Could you please suggest me any idea?

Community
  • 1
  • 1
Sangeetha
  • 496
  • 1
  • 7
  • 25
  • you mean the String your function returns does not match the long you passed? – wutzebaer Aug 08 '16 at 10:27
  • @wutzebaer No, Please check the second link where you will find the ProgressHttpEntityWrapper class. In that class it return the total bytes inside the method getCurrentProgress(). Its is not correct. Its vary from actual file size. – Sangeetha Aug 08 '16 at 10:41
  • maybe offset+len is bigger tan b.length and thus only a part of len is written?# – wutzebaer Aug 08 '16 at 10:45
  • @wutzebaer sorry i couldn't understand what you are trying to say. can u please explain it. – Sangeetha Aug 08 '16 at 12:16
  • `this.transferred += Math.min(len, b.length-off)` – wutzebaer Aug 08 '16 at 12:22
  • @wutzebaer this line is not present in that ProgressHttpEntityWrapper.java class. Do I have to add this line in that class? If so, where should i use it? – Sangeetha Aug 08 '16 at 12:31
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/120428/discussion-between-sangeetha-and-wutzebaer). – Sangeetha Aug 08 '16 at 12:42

1 Answers1

-1

okay, thank you for your response. Also i'm found why the exact file size is not returning. Its because we are assigning this call back to the entire entity like below,

  ProgressHttpEntityWrapper.ProgressCallback progressCallback = new ProgressHttpEntityWrapper.ProgressCallback() {

    @Override
    public void progress(float progress) {
        //Use the progress
    }

}

In below code I'm assigning this progress callback to my entire entity

httpPost.setEntity(new ProgressHttpEntityWrapper(entityBuilder.build(), progressCallback));

where this entity not only contain my file. It also contain my thumbnail file and other params. So the size gets differ. So i have added my file size with thumbnail size. It will be nearer size of my uploading file size the remaining bytes will be taken for my other params. Now I have Solved it.

Sangeetha
  • 496
  • 1
  • 7
  • 25
  • Not an answer, and material that forms part of a question must be posted **in the question itself**, not via a link. In this case it is clearly your copy code that is wrong, not your nunber formatting code. – user207421 Aug 09 '16 at 11:25