Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8986647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:35:59+00:00 2026-06-15T21:35:59+00:00

Here is the download function, I can use listener to get the download progress,How

  • 0

Here is the download function, I can use listener to get the download progress,How can I
get the upload progress like the download function.Thank you!

public void doGetToFile(String url, String localFilePath,CloudStatusListener listener) throws RestHttpException, HttpException {
    final HttpGet request = new HttpGet(url);
    final HttpResponse resp;
    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();

        BasicCredentialsProvider creds= new BasicCredentialsProvider();
        creds.setCredentials(new AuthScope(CloudClient.CLOUDHOST,CloudClient.CLOUDPORT),new UsernamePasswordCredentials(UserName,Password));
        httpClient.setCredentialsProvider(creds);


        resp = httpClient.execute(request);
        long totalnum=resp.getEntity().getContentLength();
        if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            FileOutputStream out = new FileOutputStream(localFilePath);

            InputStream inputStream=resp.getEntity().getContent();

            long bytesRead=0;
            int bufferSize=listener.progressInterval();
            byte b[]=new byte[bufferSize];

            int cnt=0;
            while((cnt=inputStream.read(b))!=-1)
            {
                out.write(b,0,cnt);
                bytesRead+=cnt;
                listener.onProgress(bytesRead, totalnum);
            }
            out.flush();
            out.close();

            //resp.getEntity().writeTo(out);

            out.close();
            return;
        } else {
            final String response = EntityUtils.toString(resp.getEntity());
            throw new RestHttpException(resp.getStatusLine().getStatusCode(), response);
        }
    } catch (final IOException e) {
        e.printStackTrace();
        throw new HttpException("IOException " + e.toString());
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:36:00+00:00Added an answer on June 15, 2026 at 9:36 pm

    I have solve this problem, you can do it like this:

    class FileBodyCounter extends FileBody {
        private volatile long byteCount;
        private volatile CloudStatusListener listener;
        private volatile long totalnum;
    
        public FileBodyCounter(File file,CloudStatusListener listener,long totalnum) {
            super(file);
            this.listener=listener;
            this.totalnum=totalnum;
        }
    
        public long getBytesWritten() {
            return byteCount;
        }
    
        @Override
        public void writeTo(OutputStream out) throws IOException {
            super.writeTo(new FilterOutputStream(out) {
                //
                // Other write() methods omitted for brevity. 
                // Implement for better performance
                public void write(int b) throws IOException {
                     byteCount++;
                     super.write(b);
                     if (byteCount % listener.progressInterval() == 0 ||
                        byteCount == totalnum){
                        listener.onProgress(byteCount,totalnum);
                    }
                }
            });
        }
    
    }
    

    The post function is like this:

    public String doPostMultipart(String url, 
                                    String filePath, 
                                    List<NameValuePair> params,
                                    CloudStatusListener listener
                                    ) 
                                    throws RestHttpException, 
                                            HttpException, 
                                            IOException {
    
        if (params == null) params = EMPTY_PARAMS;
    
        HttpPost request = new HttpPost(url);
    
    
        MultipartEntity reqEntity = new MultipartEntity();
        if (filePath != null && !filePath.isEmpty()) {
            FileBody bin = new FileBodyCounter(
                                        new File(filePath),
                                        listener,
                                        new FileInputStream(
                                            new File(filePath)
                                            ).available());
            reqEntity.addPart("fileUpload", bin);
        }
    
        for (NameValuePair kv : params) {
            multipartAddKV(reqEntity, kv.getName(), kv.getValue());
        }
    
        request.setEntity(reqEntity);
    
        return execute(request);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this webnoir webapp as an Eclipse project. You can download it here:
I need to use a DLL file from qsBarcode http://www.qsbarcode.de/en/index.htm (here is the download
I'd like to use Javascript to make IE6 download a file. It'll be created
Here's the deal. I'm trying to use a function to compress an image from
i got a code from here to download gmail inbox: http://davidwalsh.name/gmail-php-imap use these 2
I download the file with usage of the 1st code here . How can
Here: http://download.oracle.com/docs/html/A95907_01/diff_uni.htm#1077398 I found that on Windows Oracle is thread based, while on Unix
jQuery recommends CDN hosted or self hosted jQuery library. Here is the download path
I download gcc-code-assist from here , then do make and sudo make install. After
Here's my issue - I need to dynamically download several scripts using jQuery.getScript() and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.