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 1072737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:54:07+00:00 2026-05-16T20:54:07+00:00

We are uploading a file using the Amazon AWS Java Library and are having

  • 0

We are uploading a file using the Amazon AWS Java Library and are having difficulty obtaining upload progress. We’re currently calling the following:

File file = new File(localAsset.getVideoFilePath());
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, localAsset.getFileName(), file);
s3.putObject(putObjectRequest);

How can we set a callback to check up on file upload progress?

Thanks

  • 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-05-16T20:54:08+00:00Added an answer on May 16, 2026 at 8:54 pm

    I came upon this exact problem and wrote a simple InputStream wrapper that prints out nice progress bars:

    import java.io.IOException;
    import java.io.InputStream;
    
    import org.apache.commons.vfs.FileContent;
    import org.apache.commons.vfs.FileSystemException;
    
    public class ProgressInputStream extends InputStream {
        private final long size;
        private long progress, lastUpdate = 0;
        private final InputStream inputStream;
        private final String name;
        private boolean closed = false;
    
        public ProgressInputStream(String name, InputStream inputStream, long size) {
            this.size = size;
            this.inputStream = inputStream;
            this.name = name;
        }
    
        public ProgressInputStream(String name, FileContent content)
        throws FileSystemException {
            this.size = content.getSize();
            this.name = name;
            this.inputStream = content.getInputStream();
        }
    
        @Override
        public void close() throws IOException {
            super.close();
            if (closed) throw new IOException("already closed");
            closed = true;
        }
    
        @Override
        public int read() throws IOException {
            int count = inputStream.read();
            if (count > 0)
                progress += count;
            lastUpdate = maybeUpdateDisplay(name, progress, lastUpdate, size);
            return count;
        }
        @Override
        public int read(byte[] b, int off, int len) throws IOException {
            int count = inputStream.read(b, off, len);
            if (count > 0)
                progress += count;
            lastUpdate = maybeUpdateDisplay(name, progress, lastUpdate, size);
            return count;
        }
    
        static long maybeUpdateDisplay(String name, long progress, long lastUpdate, long size) {
            if (Config.isInUnitTests()) return lastUpdate;
            if (size < B_IN_MB/10) return lastUpdate;
            if (progress - lastUpdate > 1024 * 10) {
                lastUpdate = progress;
                int hashes = (int) (((double)progress / (double)size) * 40);
                if (hashes > 40) hashes = 40;
                String bar = StringUtils.repeat("#",
                        hashes);
                bar = StringUtils.rightPad(bar, 40);
                System.out.format("%s [%s] %.2fMB/%.2fMB\r",
                        name, bar, progress / B_IN_MB, size / B_IN_MB);
                System.out.flush();
            }
            return lastUpdate;
        }
    }
    

    (this is copy-and-pasted from live code, so you might have to do a few fixups to get it to work in your own code.)

    Then, just use the InputStream way of putting things (make sure to specify the size!) and it will make a nice progress bar for you. If you want a proper callback that’d be pretty easy to do too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Ajax file upload function with its javascript / jQuery library . When
I'm looking for a way to upload a file to s3. I am using
I'm currently using SWFUpload to upload files to my S3 bucket. And it's working
I using following code and it is successfully uploading files on my local machine.
I am trying to upload a file via ftp using FtpWebRequest as below: ftpRequest
i need to upload file without using a form. i need to do this
When uploading a file (jpeg) via a form in IE7 I am seeing a
I am writing code for uploading a file from a client to my server
I am running Ubuntu8.041. Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.3 with Suhosin-Patch configured Can't get file uploading
Do web browsers send the file size in the http header when uploading a

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.