• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Bynder / bynder-java-sdk / 35789245541

22 Sep 2026 09:52PM UTC coverage: 40.05%. First build
35789245541

push

github

ahongbynder
API-2971: fix socket timeout and OOM on large file uploads

- Thread HttpConnectionSettings through the Amazon S3 upload client
  (ApiFactory, AmazonS3Service/Impl, FileUploader, AssetService/Impl,
  BynderClientImpl) so upload timeouts are configurable instead of
  silently defaulting to OkHttp's hardcoded 10s connect/read/write
  timeouts, which caused SocketTimeoutException on large file uploads.
- Fix RXUtils.mapWithIndex to pair chunks with their index via a lazy
  map instead of zipWith(Observable.range(...)), which greedily drained
  the entire file into memory before any chunk was uploaded, causing an
  OutOfMemoryError on multi-gigabyte files.
- Switch FileUploader's chunk upload from flatMapSingle to
  concatMapSingle to process chunks strictly one at a time.
- Update HttpConnectionSettingsTest to match the new default timeout.
- Update OAuthClientCredentialsSample with the fixed timeout config and
  an additional uploadFile() example.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

17 of 45 new or added lines in 9 files covered. (37.78%)

805 of 2010 relevant lines covered (40.05%)

0.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/com/bynder/sdk/sample/OAuthClientCredentialsSample.java
1
package com.bynder.sdk.sample;
2

3
import com.bynder.sdk.configuration.Configuration;
4
import com.bynder.sdk.configuration.HttpConnectionSettings;
5
import com.bynder.sdk.configuration.OAuthSettings;
6
import com.bynder.sdk.model.Brand;
7
import com.bynder.sdk.model.Media;
8
import com.bynder.sdk.model.MediaType;
9
import com.bynder.sdk.model.upload.SaveMediaResponse;
10
import com.bynder.sdk.model.upload.UploadProgress;
11
import com.bynder.sdk.query.MediaQuery;
12
import com.bynder.sdk.query.OrderBy;
13
import com.bynder.sdk.query.upload.UploadQuery;
14
import com.bynder.sdk.service.BynderClient;
15
import com.bynder.sdk.service.asset.AssetService;
16
import com.bynder.sdk.service.oauth.OAuthService;
17
import com.bynder.sdk.util.Utils;
18
import io.reactivex.Observable;
19
import org.slf4j.Logger;
20
import org.slf4j.LoggerFactory;
21
import java.io.IOException;
22
import java.net.URISyntaxException;
23
import java.net.URL;
24
import java.util.Arrays;
25
import java.util.List;
26
import java.util.Properties;
27

28
public class OAuthClientCredentialsSample {
×
29
    private static final Logger LOG = LoggerFactory.getLogger(MediaSample.class);
×
30

31
    public static void main(final String[] args) throws IOException, URISyntaxException {
32
        /**
33
         * Loads app.properties file under src/main/resources
34
         */
35
        Properties appProperties = Utils.loadConfig("app");
×
36

37
        // Initialize BynderClient with OAuth
NEW
38
        String baseUrl = appProperties.getProperty("BASE_URL");
×
39
        OAuthSettings oAuthSettings = new OAuthSettings(appProperties.getProperty("CLIENT_ID"), appProperties.getProperty("CLIENT_SECRET"), null);
×
40
        BynderClient client = BynderClient.Builder.create(
×
41
                new Configuration.Builder(new URL(baseUrl))
42
                        .setOAuthSettings(oAuthSettings)
×
NEW
43
                        .setHttpConnectionSettings(new HttpConnectionSettings(
×
44
                                null, null, null,
NEW
45
                                120, 120, true)).build());
×
46
        List<String> scopes = Arrays.asList("offline", "asset:read", "asset:write", "asset.usage:read",
×
47
                "asset.usage:write", "collection:read", "collection:write", "meta.assetbank:read",
48
                "meta.assetbank:write", "meta.workflow:read");
49

50
        // Initialize OAuthService
51
        OAuthService oauthService = client.getOAuthService();
×
52

53
        // use client credentials
54
        oauthService.getAccessTokenClientCredentials(scopes).blockingSingle();
×
55

56
        // Initialize asset service
57
        AssetService assetService = client.getAssetService();
×
58

59
//        // Call the API to request for brands
60
//        List<Brand> brands = assetService.getBrands().blockingSingle().body();
61
//        if (brands != null && !brands.isEmpty()) {
62
//            for (Brand brand : brands) {
63
//                LOG.info("Brand ID: " + brand.getId());
64
//                LOG.info("Brand Name: " + brand.getName());
65
//                LOG.info("Brand Description: " + brand.getDescription());
66
//            }
67
//        }
68
//
69
//        // Call the API to request for media assets
70
//        MediaQuery mediaQuery =  new MediaQuery().setType(MediaType.IMAGE).setOrderBy(OrderBy.NAME_DESC).setLimit(10).setPage(1);
71
//        List<Media> mediaList = assetService.getMediaList(mediaQuery).blockingSingle().body();
72
//        if (mediaList != null && !mediaList.isEmpty()) {
73
//            for (Media media : mediaList) {
74
//                LOG.info("Media ID: " + media.getId());
75
//                LOG.info("Media Name: " + media.getName());
76
//            }
77
//        }
78

79

80
        // Upload a file
81
        // Call the API to request for brands
NEW
82
        String brandId = "";
×
83
        List<Brand> brands = assetService.getBrands().blockingSingle().body();
×
84
        if (brands != null && !brands.isEmpty()) {
×
NEW
85
            brandId = brands.get(0).getId();
×
86
        }
87

88
//        String filePath = "src/main/java/com/bynder/sdk/sample/over 5gb.mov";
89
//        LOG.info(filePath);
90
//        UploadQuery uploadQuery = new UploadQuery(filePath, brandId);
91
//        // Add the filename you want to specify in this manner
92
//        uploadQuery.setFileName("5gb.mov");
93
//        Observable<UploadProgress> uploadProgress = assetService.uploadFileWithProgress(uploadQuery);
94
//
95
//        uploadProgress.subscribe(uploadProgress1 -> {
96
//            LOG.info("Uploaded chunks: " + uploadProgress1.getUploadedChunks());
97
//            LOG.info("Transmitted bytes: " + uploadProgress1.getTransmittedBytes());
98
//            LOG.info("Total bytes: " + uploadProgress1.getTotalBytes());
99
//
100
//            if (uploadProgress1.getTransmittedBytes() == uploadProgress1.getTotalBytes()) {
101
//                LOG.info("Upload finished");
102
//            }
103
//        }, throwable -> {
104
//            LOG.error("Error uploading file", throwable);
105
//        });
106

107
        // Upload a file without progress reporting: the returned Observable emits a single
108
        // SaveMediaResponse once the upload, chunk registration, finalisation and media save
109
        // have all completed.
NEW
110
        String secondFilePath = "src/main/java/com/bynder/sdk/sample/GG_K16SPR4BTS_Bubble132.tif";
×
NEW
111
        UploadQuery secondUploadQuery = new UploadQuery(secondFilePath, brandId);
×
NEW
112
        secondUploadQuery.setFileName("GG_K16SPR4BTS_Bubble132.tif");
×
113

NEW
114
        LOG.info("Uploading: " + secondFilePath);
×
115

NEW
116
        SaveMediaResponse saveMediaResponse = assetService.uploadFile(secondUploadQuery).blockingSingle();
×
NEW
117
        if (saveMediaResponse.getSuccess()) {
×
NEW
118
            LOG.info("Upload finished successfully.");
×
NEW
119
            LOG.info("Media ID: " + saveMediaResponse.getMediaId());
×
NEW
120
            LOG.info("Portal: " + baseUrl);
×
121
        } else {
NEW
122
            LOG.error("Upload failed.");
×
123
        }
124

125
        System.exit(0);
×
126
    }
×
127
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc