Bynder / bynder-java-sdk

SDK in Java for integration with Bynder
MIT License
4 stars 24 forks source link

java sdk uploadFile vs uploadFileWithProgress #124

Open petervandepoele opened 3 weeks ago

petervandepoele commented 3 weeks ago

Hi,

I build a BynderConnector for the DAMToolkit in which for the past 4 years I have always used assetService.uploadFile(uploadQuery).blockingSingle()

But when uploading larger files I would like to be able give feedback on the progress so I was looking into Observable obUp = assetService.uploadFileWithProgress(uploadQuery) But I'm not very familiar with React Observables. Would you have an example how to work with them to output a progress

I was trying something like this but couldn't find a "next()" method:

UploadProgress nextUp=null; long bytes=0; while ( true) { nextUp=obUp.next() if (nextUp==null || nextUp.isFinished()) break; bytes=pro.getTransmittedBytes(); System.out.println("upload progress: "+bytes+" bytes "); } System.out.println("upload finished");

Thank you for any help. Peter Van de Poele damtoolkit.be

ahongbynder commented 2 weeks ago

@petervandepoele One example is subscribing to the observable. When the data is available after subscribing, the progress of the upload can be accessed based on bytes and chunks.

        Observable<UploadProgress> uploadProgress = assetService.uploadFileWithProgress(uploadQuery);

        uploadProgress.subscribe(uploadProgress1 -> {
            LOG.info("Uploaded chunks: " + uploadProgress1.getUploadedChunks());
            LOG.info("Transmitted bytes: " + uploadProgress1.getTransmittedBytes());
            LOG.info("Total bytes: " + uploadProgress1.getTotalBytes());

            if (uploadProgress1.getTransmittedBytes() == uploadProgress1.getTotalBytes()) {
                LOG.info("Upload finished");
            }
        }, throwable -> {
            LOG.error("Error uploading file", throwable);
        });
petervandepoele commented 2 weeks ago

Super, thx!

Van: ahongbynder @.> Verzonden: dinsdag 18 juni 2024 20:33 Aan: Bynder/bynder-java-sdk @.> CC: Peter Van de Poele @.>; Mention @.> Onderwerp: Re: [Bynder/bynder-java-sdk] java sdk uploadFile vs uploadFileWithProgress (Issue #124)

@petervandepoelehttps://github.com/petervandepoele One example is subscribing to the observable. When the data is available after subscribing, the progress of the upload can be accessed based on bytes and chunks.

    Observable<UploadProgress> uploadProgress = assetService.uploadFileWithProgress(uploadQuery);

    uploadProgress.subscribe(uploadProgress1 -> {

        LOG.info("Uploaded chunks: " + uploadProgress1.getUploadedChunks());

        LOG.info("Transmitted bytes: " + uploadProgress1.getTransmittedBytes());

        LOG.info("Total bytes: " + uploadProgress1.getTotalBytes());

        if (uploadProgress1.getTransmittedBytes() == uploadProgress1.getTotalBytes()) {

            LOG.info("Upload finished");

        }

    }, throwable -> {

        LOG.error("Error uploading file", throwable);

    });

— Reply to this email directly, view it on GitHubhttps://github.com/Bynder/bynder-java-sdk/issues/124#issuecomment-2176722343, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AJPL2JRUEFYHQCWWUCTU2IDZIB4NRAVCNFSM6AAAAABJDUJOMWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZWG4ZDEMZUGM. You are receiving this because you were mentioned.Message ID: @.**@.>>