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

box / box-java-sdk / #5076

07 Oct 2025 12:35PM UTC coverage: 37.132% (+0.007%) from 37.125%
#5076

push

github

web-flow
test: Change `Event.additionalDetails` field assertion in events test (box/box-codegen#858) (#1491)

18454 of 49699 relevant lines covered (37.13%)

0.37 hits per line

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

87.57
/src/main/java/com/box/sdkgen/managers/files/FilesManager.java
1
package com.box.sdkgen.managers.files;
2

3
import static com.box.sdkgen.internal.utils.UtilsManager.convertToString;
4
import static com.box.sdkgen.internal.utils.UtilsManager.entryOf;
5
import static com.box.sdkgen.internal.utils.UtilsManager.mapOf;
6
import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps;
7
import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams;
8

9
import com.box.sdkgen.box.errors.BoxSDKError;
10
import com.box.sdkgen.networking.auth.Authentication;
11
import com.box.sdkgen.networking.fetchoptions.FetchOptions;
12
import com.box.sdkgen.networking.fetchoptions.ResponseFormat;
13
import com.box.sdkgen.networking.fetchresponse.FetchResponse;
14
import com.box.sdkgen.networking.network.NetworkSession;
15
import com.box.sdkgen.schemas.filefull.FileFull;
16
import com.box.sdkgen.serialization.json.JsonManager;
17
import java.io.InputStream;
18
import java.util.Map;
19

20
public class FilesManager {
21

22
  public Authentication auth;
23

24
  public NetworkSession networkSession;
25

26
  public FilesManager() {
×
27
    this.networkSession = new NetworkSession();
×
28
  }
×
29

30
  protected FilesManager(Builder builder) {
1✔
31
    this.auth = builder.auth;
1✔
32
    this.networkSession = builder.networkSession;
1✔
33
  }
1✔
34

35
  /**
36
   * Retrieves the details about a file.
37
   *
38
   * @param fileId The unique identifier that represents a file.
39
   *     <p>The ID for any file can be determined by visiting a file in the web application and
40
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
41
   *     `file_id` is `123`. Example: "12345"
42
   */
43
  public FileFull getFileById(String fileId) {
44
    return getFileById(fileId, new GetFileByIdQueryParams(), new GetFileByIdHeaders());
1✔
45
  }
46

47
  /**
48
   * Retrieves the details about a file.
49
   *
50
   * @param fileId The unique identifier that represents a file.
51
   *     <p>The ID for any file can be determined by visiting a file in the web application and
52
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
53
   *     `file_id` is `123`. Example: "12345"
54
   * @param queryParams Query parameters of getFileById method
55
   */
56
  public FileFull getFileById(String fileId, GetFileByIdQueryParams queryParams) {
57
    return getFileById(fileId, queryParams, new GetFileByIdHeaders());
1✔
58
  }
59

60
  /**
61
   * Retrieves the details about a file.
62
   *
63
   * @param fileId The unique identifier that represents a file.
64
   *     <p>The ID for any file can be determined by visiting a file in the web application and
65
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
66
   *     `file_id` is `123`. Example: "12345"
67
   * @param headers Headers of getFileById method
68
   */
69
  public FileFull getFileById(String fileId, GetFileByIdHeaders headers) {
70
    return getFileById(fileId, new GetFileByIdQueryParams(), headers);
×
71
  }
72

73
  /**
74
   * Retrieves the details about a file.
75
   *
76
   * @param fileId The unique identifier that represents a file.
77
   *     <p>The ID for any file can be determined by visiting a file in the web application and
78
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
79
   *     `file_id` is `123`. Example: "12345"
80
   * @param queryParams Query parameters of getFileById method
81
   * @param headers Headers of getFileById method
82
   */
83
  public FileFull getFileById(
84
      String fileId, GetFileByIdQueryParams queryParams, GetFileByIdHeaders headers) {
85
    Map<String, String> queryParamsMap =
1✔
86
        prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
1✔
87
    Map<String, String> headersMap =
1✔
88
        prepareParams(
1✔
89
            mergeMaps(
1✔
90
                mapOf(
1✔
91
                    entryOf("if-none-match", convertToString(headers.getIfNoneMatch())),
1✔
92
                    entryOf("boxapi", convertToString(headers.getBoxapi())),
1✔
93
                    entryOf("x-rep-hints", convertToString(headers.getXRepHints()))),
1✔
94
                headers.getExtraHeaders()));
1✔
95
    FetchResponse response =
1✔
96
        this.networkSession
97
            .getNetworkClient()
1✔
98
            .fetch(
1✔
99
                new FetchOptions.Builder(
100
                        String.join(
1✔
101
                            "",
102
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
103
                            "/2.0/files/",
104
                            convertToString(fileId)),
1✔
105
                        "GET")
106
                    .params(queryParamsMap)
1✔
107
                    .headers(headersMap)
1✔
108
                    .responseFormat(ResponseFormat.JSON)
1✔
109
                    .auth(this.auth)
1✔
110
                    .networkSession(this.networkSession)
1✔
111
                    .build());
1✔
112
    return JsonManager.deserialize(response.getData(), FileFull.class);
1✔
113
  }
114

115
  /**
116
   * Updates a file. This can be used to rename or move a file, create a shared link, or lock a
117
   * file.
118
   *
119
   * @param fileId The unique identifier that represents a file.
120
   *     <p>The ID for any file can be determined by visiting a file in the web application and
121
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
122
   *     `file_id` is `123`. Example: "12345"
123
   */
124
  public FileFull updateFileById(String fileId) {
125
    return updateFileById(
×
126
        fileId,
127
        new UpdateFileByIdRequestBody(),
128
        new UpdateFileByIdQueryParams(),
129
        new UpdateFileByIdHeaders());
130
  }
131

132
  /**
133
   * Updates a file. This can be used to rename or move a file, create a shared link, or lock a
134
   * file.
135
   *
136
   * @param fileId The unique identifier that represents a file.
137
   *     <p>The ID for any file can be determined by visiting a file in the web application and
138
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
139
   *     `file_id` is `123`. Example: "12345"
140
   * @param requestBody Request body of updateFileById method
141
   */
142
  public FileFull updateFileById(String fileId, UpdateFileByIdRequestBody requestBody) {
143
    return updateFileById(
1✔
144
        fileId, requestBody, new UpdateFileByIdQueryParams(), new UpdateFileByIdHeaders());
145
  }
146

147
  /**
148
   * Updates a file. This can be used to rename or move a file, create a shared link, or lock a
149
   * file.
150
   *
151
   * @param fileId The unique identifier that represents a file.
152
   *     <p>The ID for any file can be determined by visiting a file in the web application and
153
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
154
   *     `file_id` is `123`. Example: "12345"
155
   * @param queryParams Query parameters of updateFileById method
156
   */
157
  public FileFull updateFileById(String fileId, UpdateFileByIdQueryParams queryParams) {
158
    return updateFileById(
×
159
        fileId, new UpdateFileByIdRequestBody(), queryParams, new UpdateFileByIdHeaders());
160
  }
161

162
  /**
163
   * Updates a file. This can be used to rename or move a file, create a shared link, or lock a
164
   * file.
165
   *
166
   * @param fileId The unique identifier that represents a file.
167
   *     <p>The ID for any file can be determined by visiting a file in the web application and
168
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
169
   *     `file_id` is `123`. Example: "12345"
170
   * @param requestBody Request body of updateFileById method
171
   * @param queryParams Query parameters of updateFileById method
172
   */
173
  public FileFull updateFileById(
174
      String fileId, UpdateFileByIdRequestBody requestBody, UpdateFileByIdQueryParams queryParams) {
175
    return updateFileById(fileId, requestBody, queryParams, new UpdateFileByIdHeaders());
1✔
176
  }
177

178
  /**
179
   * Updates a file. This can be used to rename or move a file, create a shared link, or lock a
180
   * file.
181
   *
182
   * @param fileId The unique identifier that represents a file.
183
   *     <p>The ID for any file can be determined by visiting a file in the web application and
184
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
185
   *     `file_id` is `123`. Example: "12345"
186
   * @param headers Headers of updateFileById method
187
   */
188
  public FileFull updateFileById(String fileId, UpdateFileByIdHeaders headers) {
189
    return updateFileById(
×
190
        fileId, new UpdateFileByIdRequestBody(), new UpdateFileByIdQueryParams(), headers);
191
  }
192

193
  /**
194
   * Updates a file. This can be used to rename or move a file, create a shared link, or lock a
195
   * file.
196
   *
197
   * @param fileId The unique identifier that represents a file.
198
   *     <p>The ID for any file can be determined by visiting a file in the web application and
199
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
200
   *     `file_id` is `123`. Example: "12345"
201
   * @param requestBody Request body of updateFileById method
202
   * @param headers Headers of updateFileById method
203
   */
204
  public FileFull updateFileById(
205
      String fileId, UpdateFileByIdRequestBody requestBody, UpdateFileByIdHeaders headers) {
206
    return updateFileById(fileId, requestBody, new UpdateFileByIdQueryParams(), headers);
×
207
  }
208

209
  /**
210
   * Updates a file. This can be used to rename or move a file, create a shared link, or lock a
211
   * file.
212
   *
213
   * @param fileId The unique identifier that represents a file.
214
   *     <p>The ID for any file can be determined by visiting a file in the web application and
215
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
216
   *     `file_id` is `123`. Example: "12345"
217
   * @param queryParams Query parameters of updateFileById method
218
   * @param headers Headers of updateFileById method
219
   */
220
  public FileFull updateFileById(
221
      String fileId, UpdateFileByIdQueryParams queryParams, UpdateFileByIdHeaders headers) {
222
    return updateFileById(fileId, new UpdateFileByIdRequestBody(), queryParams, headers);
×
223
  }
224

225
  /**
226
   * Updates a file. This can be used to rename or move a file, create a shared link, or lock a
227
   * file.
228
   *
229
   * @param fileId The unique identifier that represents a file.
230
   *     <p>The ID for any file can be determined by visiting a file in the web application and
231
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
232
   *     `file_id` is `123`. Example: "12345"
233
   * @param requestBody Request body of updateFileById method
234
   * @param queryParams Query parameters of updateFileById method
235
   * @param headers Headers of updateFileById method
236
   */
237
  public FileFull updateFileById(
238
      String fileId,
239
      UpdateFileByIdRequestBody requestBody,
240
      UpdateFileByIdQueryParams queryParams,
241
      UpdateFileByIdHeaders headers) {
242
    Map<String, String> queryParamsMap =
1✔
243
        prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
1✔
244
    Map<String, String> headersMap =
1✔
245
        prepareParams(
1✔
246
            mergeMaps(
1✔
247
                mapOf(entryOf("if-match", convertToString(headers.getIfMatch()))),
1✔
248
                headers.getExtraHeaders()));
1✔
249
    FetchResponse response =
1✔
250
        this.networkSession
251
            .getNetworkClient()
1✔
252
            .fetch(
1✔
253
                new FetchOptions.Builder(
254
                        String.join(
1✔
255
                            "",
256
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
257
                            "/2.0/files/",
258
                            convertToString(fileId)),
1✔
259
                        "PUT")
260
                    .params(queryParamsMap)
1✔
261
                    .headers(headersMap)
1✔
262
                    .data(JsonManager.serialize(requestBody))
1✔
263
                    .contentType("application/json")
1✔
264
                    .responseFormat(ResponseFormat.JSON)
1✔
265
                    .auth(this.auth)
1✔
266
                    .networkSession(this.networkSession)
1✔
267
                    .build());
1✔
268
    return JsonManager.deserialize(response.getData(), FileFull.class);
1✔
269
  }
270

271
  /**
272
   * Deletes a file, either permanently or by moving it to the trash.
273
   *
274
   * <p>The enterprise settings determine whether the item will be permanently deleted from Box or
275
   * moved to the trash.
276
   *
277
   * @param fileId The unique identifier that represents a file.
278
   *     <p>The ID for any file can be determined by visiting a file in the web application and
279
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
280
   *     `file_id` is `123`. Example: "12345"
281
   */
282
  public void deleteFileById(String fileId) {
283
    deleteFileById(fileId, new DeleteFileByIdHeaders());
1✔
284
  }
1✔
285

286
  /**
287
   * Deletes a file, either permanently or by moving it to the trash.
288
   *
289
   * <p>The enterprise settings determine whether the item will be permanently deleted from Box or
290
   * moved to the trash.
291
   *
292
   * @param fileId The unique identifier that represents a file.
293
   *     <p>The ID for any file can be determined by visiting a file in the web application and
294
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
295
   *     `file_id` is `123`. Example: "12345"
296
   * @param headers Headers of deleteFileById method
297
   */
298
  public void deleteFileById(String fileId, DeleteFileByIdHeaders headers) {
299
    Map<String, String> headersMap =
1✔
300
        prepareParams(
1✔
301
            mergeMaps(
1✔
302
                mapOf(entryOf("if-match", convertToString(headers.getIfMatch()))),
1✔
303
                headers.getExtraHeaders()));
1✔
304
    FetchResponse response =
1✔
305
        this.networkSession
306
            .getNetworkClient()
1✔
307
            .fetch(
1✔
308
                new FetchOptions.Builder(
309
                        String.join(
1✔
310
                            "",
311
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
312
                            "/2.0/files/",
313
                            convertToString(fileId)),
1✔
314
                        "DELETE")
315
                    .headers(headersMap)
1✔
316
                    .responseFormat(ResponseFormat.NO_CONTENT)
1✔
317
                    .auth(this.auth)
1✔
318
                    .networkSession(this.networkSession)
1✔
319
                    .build());
1✔
320
  }
1✔
321

322
  /**
323
   * Creates a copy of a file.
324
   *
325
   * @param fileId The unique identifier that represents a file.
326
   *     <p>The ID for any file can be determined by visiting a file in the web application and
327
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
328
   *     `file_id` is `123`. Example: "12345"
329
   * @param requestBody Request body of copyFile method
330
   */
331
  public FileFull copyFile(String fileId, CopyFileRequestBody requestBody) {
332
    return copyFile(fileId, requestBody, new CopyFileQueryParams(), new CopyFileHeaders());
1✔
333
  }
334

335
  /**
336
   * Creates a copy of a file.
337
   *
338
   * @param fileId The unique identifier that represents a file.
339
   *     <p>The ID for any file can be determined by visiting a file in the web application and
340
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
341
   *     `file_id` is `123`. Example: "12345"
342
   * @param requestBody Request body of copyFile method
343
   * @param queryParams Query parameters of copyFile method
344
   */
345
  public FileFull copyFile(
346
      String fileId, CopyFileRequestBody requestBody, CopyFileQueryParams queryParams) {
347
    return copyFile(fileId, requestBody, queryParams, new CopyFileHeaders());
×
348
  }
349

350
  /**
351
   * Creates a copy of a file.
352
   *
353
   * @param fileId The unique identifier that represents a file.
354
   *     <p>The ID for any file can be determined by visiting a file in the web application and
355
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
356
   *     `file_id` is `123`. Example: "12345"
357
   * @param requestBody Request body of copyFile method
358
   * @param headers Headers of copyFile method
359
   */
360
  public FileFull copyFile(
361
      String fileId, CopyFileRequestBody requestBody, CopyFileHeaders headers) {
362
    return copyFile(fileId, requestBody, new CopyFileQueryParams(), headers);
×
363
  }
364

365
  /**
366
   * Creates a copy of a file.
367
   *
368
   * @param fileId The unique identifier that represents a file.
369
   *     <p>The ID for any file can be determined by visiting a file in the web application and
370
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
371
   *     `file_id` is `123`. Example: "12345"
372
   * @param requestBody Request body of copyFile method
373
   * @param queryParams Query parameters of copyFile method
374
   * @param headers Headers of copyFile method
375
   */
376
  public FileFull copyFile(
377
      String fileId,
378
      CopyFileRequestBody requestBody,
379
      CopyFileQueryParams queryParams,
380
      CopyFileHeaders headers) {
381
    Map<String, String> queryParamsMap =
1✔
382
        prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
1✔
383
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
384
    FetchResponse response =
1✔
385
        this.networkSession
386
            .getNetworkClient()
1✔
387
            .fetch(
1✔
388
                new FetchOptions.Builder(
389
                        String.join(
1✔
390
                            "",
391
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
392
                            "/2.0/files/",
393
                            convertToString(fileId),
1✔
394
                            "/copy"),
395
                        "POST")
396
                    .params(queryParamsMap)
1✔
397
                    .headers(headersMap)
1✔
398
                    .data(JsonManager.serialize(requestBody))
1✔
399
                    .contentType("application/json")
1✔
400
                    .responseFormat(ResponseFormat.JSON)
1✔
401
                    .auth(this.auth)
1✔
402
                    .networkSession(this.networkSession)
1✔
403
                    .build());
1✔
404
    return JsonManager.deserialize(response.getData(), FileFull.class);
1✔
405
  }
406

407
  /**
408
   * Retrieves a thumbnail, or smaller image representation, of a file.
409
   *
410
   * <p>Sizes of `32x32`,`64x64`, `128x128`, and `256x256` can be returned in the `.png` format and
411
   * sizes of `32x32`, `160x160`, and `320x320` can be returned in the `.jpg` format.
412
   *
413
   * <p>Thumbnails can be generated for the image and video file formats listed [found on our
414
   * community site][1].
415
   *
416
   * <p>[1]:
417
   * https://community.box.com/t5/Migrating-and-Previewing-Content/File-Types-and-Fonts-Supported-in-Box-Content-Preview/ta-p/327
418
   *
419
   * @param fileId The unique identifier that represents a file.
420
   *     <p>The ID for any file can be determined by visiting a file in the web application and
421
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
422
   *     `file_id` is `123`. Example: "12345"
423
   * @param extension The file format for the thumbnail. Example: "png"
424
   */
425
  public String getFileThumbnailUrl(String fileId, GetFileThumbnailUrlExtension extension) {
426
    return getFileThumbnailUrl(
1✔
427
        fileId, extension, new GetFileThumbnailUrlQueryParams(), new GetFileThumbnailUrlHeaders());
428
  }
429

430
  /**
431
   * Retrieves a thumbnail, or smaller image representation, of a file.
432
   *
433
   * <p>Sizes of `32x32`,`64x64`, `128x128`, and `256x256` can be returned in the `.png` format and
434
   * sizes of `32x32`, `160x160`, and `320x320` can be returned in the `.jpg` format.
435
   *
436
   * <p>Thumbnails can be generated for the image and video file formats listed [found on our
437
   * community site][1].
438
   *
439
   * <p>[1]:
440
   * https://community.box.com/t5/Migrating-and-Previewing-Content/File-Types-and-Fonts-Supported-in-Box-Content-Preview/ta-p/327
441
   *
442
   * @param fileId The unique identifier that represents a file.
443
   *     <p>The ID for any file can be determined by visiting a file in the web application and
444
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
445
   *     `file_id` is `123`. Example: "12345"
446
   * @param extension The file format for the thumbnail. Example: "png"
447
   * @param queryParams Query parameters of getFileThumbnailById method
448
   */
449
  public String getFileThumbnailUrl(
450
      String fileId,
451
      GetFileThumbnailUrlExtension extension,
452
      GetFileThumbnailUrlQueryParams queryParams) {
453
    return getFileThumbnailUrl(fileId, extension, queryParams, new GetFileThumbnailUrlHeaders());
×
454
  }
455

456
  /**
457
   * Retrieves a thumbnail, or smaller image representation, of a file.
458
   *
459
   * <p>Sizes of `32x32`,`64x64`, `128x128`, and `256x256` can be returned in the `.png` format and
460
   * sizes of `32x32`, `160x160`, and `320x320` can be returned in the `.jpg` format.
461
   *
462
   * <p>Thumbnails can be generated for the image and video file formats listed [found on our
463
   * community site][1].
464
   *
465
   * <p>[1]:
466
   * https://community.box.com/t5/Migrating-and-Previewing-Content/File-Types-and-Fonts-Supported-in-Box-Content-Preview/ta-p/327
467
   *
468
   * @param fileId The unique identifier that represents a file.
469
   *     <p>The ID for any file can be determined by visiting a file in the web application and
470
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
471
   *     `file_id` is `123`. Example: "12345"
472
   * @param extension The file format for the thumbnail. Example: "png"
473
   * @param headers Headers of getFileThumbnailById method
474
   */
475
  public String getFileThumbnailUrl(
476
      String fileId, GetFileThumbnailUrlExtension extension, GetFileThumbnailUrlHeaders headers) {
477
    return getFileThumbnailUrl(fileId, extension, new GetFileThumbnailUrlQueryParams(), headers);
×
478
  }
479

480
  /**
481
   * Retrieves a thumbnail, or smaller image representation, of a file.
482
   *
483
   * <p>Sizes of `32x32`,`64x64`, `128x128`, and `256x256` can be returned in the `.png` format and
484
   * sizes of `32x32`, `160x160`, and `320x320` can be returned in the `.jpg` format.
485
   *
486
   * <p>Thumbnails can be generated for the image and video file formats listed [found on our
487
   * community site][1].
488
   *
489
   * <p>[1]:
490
   * https://community.box.com/t5/Migrating-and-Previewing-Content/File-Types-and-Fonts-Supported-in-Box-Content-Preview/ta-p/327
491
   *
492
   * @param fileId The unique identifier that represents a file.
493
   *     <p>The ID for any file can be determined by visiting a file in the web application and
494
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
495
   *     `file_id` is `123`. Example: "12345"
496
   * @param extension The file format for the thumbnail. Example: "png"
497
   * @param queryParams Query parameters of getFileThumbnailById method
498
   * @param headers Headers of getFileThumbnailById method
499
   */
500
  public String getFileThumbnailUrl(
501
      String fileId,
502
      GetFileThumbnailUrlExtension extension,
503
      GetFileThumbnailUrlQueryParams queryParams,
504
      GetFileThumbnailUrlHeaders headers) {
505
    Map<String, String> queryParamsMap =
1✔
506
        prepareParams(
1✔
507
            mapOf(
1✔
508
                entryOf("min_height", convertToString(queryParams.getMinHeight())),
1✔
509
                entryOf("min_width", convertToString(queryParams.getMinWidth())),
1✔
510
                entryOf("max_height", convertToString(queryParams.getMaxHeight())),
1✔
511
                entryOf("max_width", convertToString(queryParams.getMaxWidth()))));
1✔
512
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
513
    FetchResponse response =
1✔
514
        this.networkSession
515
            .getNetworkClient()
1✔
516
            .fetch(
1✔
517
                new FetchOptions.Builder(
518
                        String.join(
1✔
519
                            "",
520
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
521
                            "/2.0/files/",
522
                            convertToString(fileId),
1✔
523
                            "/thumbnail.",
524
                            convertToString(extension)),
1✔
525
                        "GET")
526
                    .params(queryParamsMap)
1✔
527
                    .headers(headersMap)
1✔
528
                    .responseFormat(ResponseFormat.NO_CONTENT)
1✔
529
                    .auth(this.auth)
1✔
530
                    .networkSession(this.networkSession)
1✔
531
                    .followRedirects(false)
1✔
532
                    .build());
1✔
533
    if (response.getHeaders().containsKey("location")) {
1✔
534
      return response.getHeaders().get("location");
1✔
535
    }
536
    if (response.getHeaders().containsKey("Location")) {
×
537
      return response.getHeaders().get("Location");
×
538
    }
539
    throw new BoxSDKError("No location header in response");
×
540
  }
541

542
  /**
543
   * Retrieves a thumbnail, or smaller image representation, of a file.
544
   *
545
   * <p>Sizes of `32x32`,`64x64`, `128x128`, and `256x256` can be returned in the `.png` format and
546
   * sizes of `32x32`, `160x160`, and `320x320` can be returned in the `.jpg` format.
547
   *
548
   * <p>Thumbnails can be generated for the image and video file formats listed [found on our
549
   * community site][1].
550
   *
551
   * <p>[1]:
552
   * https://community.box.com/t5/Migrating-and-Previewing-Content/File-Types-and-Fonts-Supported-in-Box-Content-Preview/ta-p/327
553
   *
554
   * @param fileId The unique identifier that represents a file.
555
   *     <p>The ID for any file can be determined by visiting a file in the web application and
556
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
557
   *     `file_id` is `123`. Example: "12345"
558
   * @param extension The file format for the thumbnail. Example: "png"
559
   */
560
  public InputStream getFileThumbnailById(String fileId, GetFileThumbnailByIdExtension extension) {
561
    return getFileThumbnailById(
1✔
562
        fileId,
563
        extension,
564
        new GetFileThumbnailByIdQueryParams(),
565
        new GetFileThumbnailByIdHeaders());
566
  }
567

568
  /**
569
   * Retrieves a thumbnail, or smaller image representation, of a file.
570
   *
571
   * <p>Sizes of `32x32`,`64x64`, `128x128`, and `256x256` can be returned in the `.png` format and
572
   * sizes of `32x32`, `160x160`, and `320x320` can be returned in the `.jpg` format.
573
   *
574
   * <p>Thumbnails can be generated for the image and video file formats listed [found on our
575
   * community site][1].
576
   *
577
   * <p>[1]:
578
   * https://community.box.com/t5/Migrating-and-Previewing-Content/File-Types-and-Fonts-Supported-in-Box-Content-Preview/ta-p/327
579
   *
580
   * @param fileId The unique identifier that represents a file.
581
   *     <p>The ID for any file can be determined by visiting a file in the web application and
582
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
583
   *     `file_id` is `123`. Example: "12345"
584
   * @param extension The file format for the thumbnail. Example: "png"
585
   * @param queryParams Query parameters of getFileThumbnailById method
586
   */
587
  public InputStream getFileThumbnailById(
588
      String fileId,
589
      GetFileThumbnailByIdExtension extension,
590
      GetFileThumbnailByIdQueryParams queryParams) {
591
    return getFileThumbnailById(fileId, extension, queryParams, new GetFileThumbnailByIdHeaders());
×
592
  }
593

594
  /**
595
   * Retrieves a thumbnail, or smaller image representation, of a file.
596
   *
597
   * <p>Sizes of `32x32`,`64x64`, `128x128`, and `256x256` can be returned in the `.png` format and
598
   * sizes of `32x32`, `160x160`, and `320x320` can be returned in the `.jpg` format.
599
   *
600
   * <p>Thumbnails can be generated for the image and video file formats listed [found on our
601
   * community site][1].
602
   *
603
   * <p>[1]:
604
   * https://community.box.com/t5/Migrating-and-Previewing-Content/File-Types-and-Fonts-Supported-in-Box-Content-Preview/ta-p/327
605
   *
606
   * @param fileId The unique identifier that represents a file.
607
   *     <p>The ID for any file can be determined by visiting a file in the web application and
608
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
609
   *     `file_id` is `123`. Example: "12345"
610
   * @param extension The file format for the thumbnail. Example: "png"
611
   * @param headers Headers of getFileThumbnailById method
612
   */
613
  public InputStream getFileThumbnailById(
614
      String fileId, GetFileThumbnailByIdExtension extension, GetFileThumbnailByIdHeaders headers) {
615
    return getFileThumbnailById(fileId, extension, new GetFileThumbnailByIdQueryParams(), headers);
×
616
  }
617

618
  /**
619
   * Retrieves a thumbnail, or smaller image representation, of a file.
620
   *
621
   * <p>Sizes of `32x32`,`64x64`, `128x128`, and `256x256` can be returned in the `.png` format and
622
   * sizes of `32x32`, `160x160`, and `320x320` can be returned in the `.jpg` format.
623
   *
624
   * <p>Thumbnails can be generated for the image and video file formats listed [found on our
625
   * community site][1].
626
   *
627
   * <p>[1]:
628
   * https://community.box.com/t5/Migrating-and-Previewing-Content/File-Types-and-Fonts-Supported-in-Box-Content-Preview/ta-p/327
629
   *
630
   * @param fileId The unique identifier that represents a file.
631
   *     <p>The ID for any file can be determined by visiting a file in the web application and
632
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
633
   *     `file_id` is `123`. Example: "12345"
634
   * @param extension The file format for the thumbnail. Example: "png"
635
   * @param queryParams Query parameters of getFileThumbnailById method
636
   * @param headers Headers of getFileThumbnailById method
637
   */
638
  public InputStream getFileThumbnailById(
639
      String fileId,
640
      GetFileThumbnailByIdExtension extension,
641
      GetFileThumbnailByIdQueryParams queryParams,
642
      GetFileThumbnailByIdHeaders headers) {
643
    Map<String, String> queryParamsMap =
1✔
644
        prepareParams(
1✔
645
            mapOf(
1✔
646
                entryOf("min_height", convertToString(queryParams.getMinHeight())),
1✔
647
                entryOf("min_width", convertToString(queryParams.getMinWidth())),
1✔
648
                entryOf("max_height", convertToString(queryParams.getMaxHeight())),
1✔
649
                entryOf("max_width", convertToString(queryParams.getMaxWidth()))));
1✔
650
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
651
    FetchResponse response =
1✔
652
        this.networkSession
653
            .getNetworkClient()
1✔
654
            .fetch(
1✔
655
                new FetchOptions.Builder(
656
                        String.join(
1✔
657
                            "",
658
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
659
                            "/2.0/files/",
660
                            convertToString(fileId),
1✔
661
                            "/thumbnail.",
662
                            convertToString(extension)),
1✔
663
                        "GET")
664
                    .params(queryParamsMap)
1✔
665
                    .headers(headersMap)
1✔
666
                    .responseFormat(ResponseFormat.BINARY)
1✔
667
                    .auth(this.auth)
1✔
668
                    .networkSession(this.networkSession)
1✔
669
                    .build());
1✔
670
    if (convertToString(response.getStatus()).equals("202")) {
1✔
671
      return null;
×
672
    }
673
    return response.getContent();
1✔
674
  }
675

676
  public Authentication getAuth() {
677
    return auth;
×
678
  }
679

680
  public NetworkSession getNetworkSession() {
681
    return networkSession;
×
682
  }
683

684
  public static class Builder {
685

686
    protected Authentication auth;
687

688
    protected NetworkSession networkSession;
689

690
    public Builder() {
1✔
691
      this.networkSession = new NetworkSession();
1✔
692
    }
1✔
693

694
    public Builder auth(Authentication auth) {
695
      this.auth = auth;
1✔
696
      return this;
1✔
697
    }
698

699
    public Builder networkSession(NetworkSession networkSession) {
700
      this.networkSession = networkSession;
1✔
701
      return this;
1✔
702
    }
703

704
    public FilesManager build() {
705
      return new FilesManager(this);
1✔
706
    }
707
  }
708
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc