Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No method to get the file downloading/uploading progress #66

Closed
thekindJose opened this issue Sep 2, 2016 · 35 comments
Closed

No method to get the file downloading/uploading progress #66

thekindJose opened this issue Sep 2, 2016 · 35 comments

Comments

@thekindJose
Copy link

Hi,
I'm trying to integrate the v2 dropbox sdk into my android app.
I'm working on downloading files, but I cannot find anything in the API which notifies me regarding the downloading progress (as there was before on v1.6, i.e. the ProgressListener).
Am I missing something or have you removed this important feature?

Thanks!

@greg-db
Copy link
Contributor

greg-db commented Sep 2, 2016

The API v2 Java SDK doesn't offer progress listeners, but we'll consider this a feature request. (The v2 Java SDK isn't built on the v1 Android Core SDK, so it didn't inherit the progress listeners from there.)

@thekindJose
Copy link
Author

Hi @greg-db. Is it possible to know when could we expect it to be done? We would like to migrate to v2 on our android app, but we do not want to lose functionality. If user is downloading a file, user wants to know how is the progress of the download going. Even in Java I think it is an important thing to have, isn't it? I'm not talking of a ProgressListener android specific, but at least a callback to get notified. Looking at the code seems to be closed for extension.

@greg-db
Copy link
Contributor

greg-db commented Sep 26, 2016

I don't have a timeline to offer for this unfortunately. Apologies I don't have any more useful to share!

@thekindJose
Copy link
Author

thekindJose commented Sep 27, 2016

@greg-db, may I know which version of the SDK you are using for the android dropbox app? I've got installed on my phone dropbox version 15.2.2 and on this apk there is a progressbar both for the downloads and for the uploads. Are you using a different API?
I've looked also at the Objective-C dropbox v2 SDK, and there are listeners both for the uploads and the downloads.

@thekindJose thekindJose changed the title No method to get the file downloading progress No method to get the file downloading/uploading progress Sep 27, 2016
@cakoose
Copy link
Contributor

cakoose commented Sep 27, 2016

@thekindJose: As a workaround, you can create a wrapper OutputStream that tracks progress. Something like:

public class ProgressOutputStream extends OutputStream {
    ...
    public ProgressOutputStream(long totalSize, OutputStream underlying, Listener listener) {
        this.underlying = underlying;
        this.listener = listener;
        this.completed = 0;
        this.totalSize = totalSize;
    }

    @Override
    public void write(byte[] data, int off, int len) throws IOException {
        this.underlying.write(data, off, len);
        track(len);
    }

    @Override
    public void write(byte[] data) throws IOException {
        this.underlying.write(data);
        track(data.length);
    }

    @Override
    public void write(int c) {
        this.underlying.write(c);
        track(1)
    }

    private void track(int len) {
        this.completed += len;
        this.listener.progress(this.completed, this.totalSize);
    }

    public interface Listener {
        public void progress(long completed, long totalSize);
    }
}

Then, with the SDK:

DbxClientV2 client = ...
DbxDownloader<FileMetadata> dl = client.files().download("/remote-file-path");
long size = dl.getResult().size;

FileOutputStream fout = new FileOutputStream("local-file");
dl.download(new ProgressOutputStream(size, fout, new ProgressOutputStream.Listener() {
    void progress(long completed, long totalSize) {
        // update progress bar here ...
    }
});

@LitbLeo
Copy link

LitbLeo commented Oct 22, 2016

Hi @cakoose, i used your method,it was just worked by downloading.When i used InputStream to resovle the upload,it doesn't work.Code like this:

public class ProgressAwareInputStream extends InputStream {
    private InputStream wrappedInputStream;
    private long size;
    private long counter;
    private InputStreamListener listener;

    public ProgressAwareInputStream(InputStream in, long size, InputStreamListener listener) {
        wrappedInputStream = in;
        this.size = size;
        this.listener = listener;
    }


    @Override
    public int read() throws IOException {
        int retVal = wrappedInputStream.read();
        counter += 1;
        check(retVal);
        return retVal;
    }

    @Override
    public int read(byte[] b) throws IOException {
        int retVal = wrappedInputStream.read(b);
        counter += retVal;
        check(retVal);
        return retVal;
    }

    @Override
    public int read(byte[] b, int offset, int length) throws IOException {
        int retVal = wrappedInputStream.read(b, offset, length);
        counter += retVal;
        check(retVal);
        return retVal;
    }

    private void check(int retVal) {
        if (retVal != -1) {
            listener.uploadProgress(counter, size);
        }
    }

    /**
     * Interface for classes that want to monitor this input stream
     */
    public interface InputStreamListener{
        void uploadProgress(long completed, long totalSize);
    }
}

This method just lisenning local stream but not remote.Could you help me ?Thanks!

@skywalkerlw
Copy link

+1. to show uploading progress is quite a basic and required function, hope this function can be added as soon as possible

@SDPrio
Copy link

SDPrio commented Feb 16, 2017

+1 I am also surprised that such an essential feature is not included.

@nzala
Copy link

nzala commented Apr 18, 2017

an essential feature is not included.

@tactoth
Copy link

tactoth commented May 27, 2017

And you just retired the V1 API without this essential feature in the new V2 api you are promoting ;(

@jiuyangzhao
Copy link
Contributor

jiuyangzhao commented May 31, 2017

@cakoose already provided a method to wrap OutputStream and tracking download progress.

For Uploading. In V1 android SDK we provided a convenient class ChunkedUploader. In API V2 we no longer provide it but its actually quite simple to implement your own. You can split you file into small chunks and send them through /upload_session/start, /upload_session/append_v2 and /upload_session/finish just like our example. Also because you split the file you self it's very simple to keep tracking the uploading progress. This is exactly how we implement upload progress listener in V1.

@ikzjfr0
Copy link

ikzjfr0 commented May 31, 2017

@jiuyangzhao don't you think this solution is a little complicated? you should provide a friendly API for upload progress :) . By the way, there's a bug in your chunked upload: #88

@tactoth
Copy link

tactoth commented May 31, 2017

The whole point of using this library is that I don't want to be wrapping all the rest calls.

@greg-db
Copy link
Contributor

greg-db commented Jun 1, 2017

Thanks for the feedback! I definitely see how it would be more helpful to offer a simplified interface for this.

@jamesdwlee
Copy link

it's announced the dropbox api v1 will be retired as of 6/28/2017 but still no news to support ProgressMonitor? Without providing the essential function, how v1 can be retried and dropbox force all apps to move to v2?

@greg-db
Copy link
Contributor

greg-db commented Jun 25, 2017

I don't have an update on this feature request right now.

Note that we actually just announced a general extension for access to API v1 though, until 9/28/2017:

https://blogs.dropbox.com/developers/2017/06/updated-api-v1-deprecation-timeline/

@menglingpeng
Copy link

@LitbLeo thank your uploadProgress method,but i think it has a little mistake.
check(counter);instead of check(retVal);
then it works very well.

@isabsent
Copy link

isabsent commented Jul 1, 2017

Dear Dropbox team! You are forcing developers to migrate on v.2, but you have not provide essential API calls for it! More over, you are writing in your announcement

Developers have asked us for more time to finish updating their apps

while developers ask you to provide in v.2 methods that exist in v.1 during last year! But you do nothing for this! Your announcement should be changed to:

We are not able to write consistent API for v.2, so we are not going to provide painless migration from v.1 to v.2 and you have to implement chunked upload yourself.

The best way in this situation is do not turn off v.1 support until you are not write consistent v.2 release.

@greg-db
Copy link
Contributor

greg-db commented Jul 3, 2017

Thanks for the additional feedback! I'm sending it to the team.

@jamesdwlee
Copy link

Any update from DropBox? 9/28 is still the deadline without having any update from DropBox yet?

@greg-db
Copy link
Contributor

greg-db commented Sep 1, 2017

I don't have an update on this feature request. I'll follow up here if/when I do.

And yes, API v1 is planned for retirement on 9/28/17. You can find the full timeline and information in the blog post.

@assassinshadow0
Copy link

@pteale
Copy link

pteale commented Oct 13, 2017

Why the hell did you turn off the v1 API when v2 is clearly incomplete
You cant say your adding upload/download functionality and then not provide progress listeners, only a moron would implement it this way
Get this fixed.

@dkijkuit
Copy link

dkijkuit commented Oct 17, 2017

Chunked file upload, wow... 👎

You just made something trivial as monitoring progress, much more difficult.

@greg-db
Copy link
Contributor

greg-db commented Nov 21, 2017

Thanks for the feedback everyone!

@saorisato The "open with" test is just internal functionality for Dropbox's use. You can safely ignore that.

Also, can you open an issue with the steps to reproduce and the stack trace for the crash your saw? Thanks in advance!

@johnnyb15613
Copy link

I cannot believe that over a year after this issue was opened it is still not rectified. You guys do know that you are a leader in cloud storage, yet your API has no way to track the progress of an upload or download.
You deserve whatever downfall ensues, this functionality is as pertinent to file storage as all CRUD operations are. Piss poor, putting it lightly. Even though v1 didnt do it well, it at least did it. Taking critical steps backwards. And not addressing it whatsoever. Booooooooooo

@nebulabox
Copy link

The team should be shamed.

@goxr3plus
Copy link

@cakoose Thank you so much for the code for downloading :) Can we have also some code for uploading , i am braking stuff in house because the library doesn't have it lol .

@jiuyangzhao
Copy link
Contributor

We will support this in next release.

@goxr3plus
Copy link

goxr3plus commented Jul 21, 2018 via email

@alirezaomidi
Copy link

@jiuyangzhao When does the next release happen?

@goxr3plus
Copy link

goxr3plus commented Jul 31, 2018 via email

@goxr3plus
Copy link

@jiuyangzhao :) I see you added it , can we have the release i love you so much :)

@greg-db
Copy link
Contributor

greg-db commented Sep 18, 2018

This has been released in v3.0.9. There's an example of using it with with the uploadAndFinish method for an upload here.

It works the same way with file downloads; the download method optionally takes a ProgressListener parameter the same way.

@greg-db greg-db closed this as completed Sep 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests