001package com.box.sdkgen.managers.files; 002 003import static com.box.sdkgen.internal.utils.UtilsManager.convertToString; 004import static com.box.sdkgen.internal.utils.UtilsManager.entryOf; 005import static com.box.sdkgen.internal.utils.UtilsManager.mapOf; 006import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps; 007import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams; 008 009import com.box.sdkgen.box.errors.BoxSDKError; 010import com.box.sdkgen.networking.auth.Authentication; 011import com.box.sdkgen.networking.fetchoptions.FetchOptions; 012import com.box.sdkgen.networking.fetchoptions.ResponseFormat; 013import com.box.sdkgen.networking.fetchresponse.FetchResponse; 014import com.box.sdkgen.networking.network.NetworkSession; 015import com.box.sdkgen.schemas.filefull.FileFull; 016import com.box.sdkgen.serialization.json.JsonManager; 017import java.io.InputStream; 018import java.util.Map; 019 020public class FilesManager { 021 022 public Authentication auth; 023 024 public NetworkSession networkSession; 025 026 public FilesManager() { 027 this.networkSession = new NetworkSession(); 028 } 029 030 protected FilesManager(Builder builder) { 031 this.auth = builder.auth; 032 this.networkSession = builder.networkSession; 033 } 034 035 /** 036 * Retrieves the details about a file. 037 * 038 * @param fileId The unique identifier that represents a file. 039 * <p>The ID for any file can be determined by visiting a file in the web application and 040 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 041 * `file_id` is `123`. Example: "12345" 042 */ 043 public FileFull getFileById(String fileId) { 044 return getFileById(fileId, new GetFileByIdQueryParams(), new GetFileByIdHeaders()); 045 } 046 047 /** 048 * Retrieves the details about a file. 049 * 050 * @param fileId The unique identifier that represents a file. 051 * <p>The ID for any file can be determined by visiting a file in the web application and 052 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 053 * `file_id` is `123`. Example: "12345" 054 * @param queryParams Query parameters of getFileById method 055 */ 056 public FileFull getFileById(String fileId, GetFileByIdQueryParams queryParams) { 057 return getFileById(fileId, queryParams, new GetFileByIdHeaders()); 058 } 059 060 /** 061 * Retrieves the details about a file. 062 * 063 * @param fileId The unique identifier that represents a file. 064 * <p>The ID for any file can be determined by visiting a file in the web application and 065 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 066 * `file_id` is `123`. Example: "12345" 067 * @param headers Headers of getFileById method 068 */ 069 public FileFull getFileById(String fileId, GetFileByIdHeaders headers) { 070 return getFileById(fileId, new GetFileByIdQueryParams(), headers); 071 } 072 073 /** 074 * Retrieves the details about a file. 075 * 076 * @param fileId The unique identifier that represents a file. 077 * <p>The ID for any file can be determined by visiting a file in the web application and 078 * copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the 079 * `file_id` is `123`. Example: "12345" 080 * @param queryParams Query parameters of getFileById method 081 * @param headers Headers of getFileById method 082 */ 083 public FileFull getFileById( 084 String fileId, GetFileByIdQueryParams queryParams, GetFileByIdHeaders headers) { 085 Map<String, String> queryParamsMap = 086 prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields())))); 087 Map<String, String> headersMap = 088 prepareParams( 089 mergeMaps( 090 mapOf( 091 entryOf("if-none-match", convertToString(headers.getIfNoneMatch())), 092 entryOf("boxapi", convertToString(headers.getBoxapi())), 093 entryOf("x-rep-hints", convertToString(headers.getXRepHints()))), 094 headers.getExtraHeaders())); 095 FetchResponse response = 096 this.networkSession 097 .getNetworkClient() 098 .fetch( 099 new FetchOptions.Builder( 100 String.join( 101 "", 102 this.networkSession.getBaseUrls().getBaseUrl(), 103 "/2.0/files/", 104 convertToString(fileId)), 105 "GET") 106 .params(queryParamsMap) 107 .headers(headersMap) 108 .responseFormat(ResponseFormat.JSON) 109 .auth(this.auth) 110 .networkSession(this.networkSession) 111 .build()); 112 return JsonManager.deserialize(response.getData(), FileFull.class); 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( 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()); 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 = 243 prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields())))); 244 Map<String, String> headersMap = 245 prepareParams( 246 mergeMaps( 247 mapOf(entryOf("if-match", convertToString(headers.getIfMatch()))), 248 headers.getExtraHeaders())); 249 FetchResponse response = 250 this.networkSession 251 .getNetworkClient() 252 .fetch( 253 new FetchOptions.Builder( 254 String.join( 255 "", 256 this.networkSession.getBaseUrls().getBaseUrl(), 257 "/2.0/files/", 258 convertToString(fileId)), 259 "PUT") 260 .params(queryParamsMap) 261 .headers(headersMap) 262 .data(JsonManager.serialize(requestBody)) 263 .contentType("application/json") 264 .responseFormat(ResponseFormat.JSON) 265 .auth(this.auth) 266 .networkSession(this.networkSession) 267 .build()); 268 return JsonManager.deserialize(response.getData(), FileFull.class); 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()); 284 } 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 = 300 prepareParams( 301 mergeMaps( 302 mapOf(entryOf("if-match", convertToString(headers.getIfMatch()))), 303 headers.getExtraHeaders())); 304 FetchResponse response = 305 this.networkSession 306 .getNetworkClient() 307 .fetch( 308 new FetchOptions.Builder( 309 String.join( 310 "", 311 this.networkSession.getBaseUrls().getBaseUrl(), 312 "/2.0/files/", 313 convertToString(fileId)), 314 "DELETE") 315 .headers(headersMap) 316 .responseFormat(ResponseFormat.NO_CONTENT) 317 .auth(this.auth) 318 .networkSession(this.networkSession) 319 .build()); 320 } 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()); 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 = 382 prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields())))); 383 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 384 FetchResponse response = 385 this.networkSession 386 .getNetworkClient() 387 .fetch( 388 new FetchOptions.Builder( 389 String.join( 390 "", 391 this.networkSession.getBaseUrls().getBaseUrl(), 392 "/2.0/files/", 393 convertToString(fileId), 394 "/copy"), 395 "POST") 396 .params(queryParamsMap) 397 .headers(headersMap) 398 .data(JsonManager.serialize(requestBody)) 399 .contentType("application/json") 400 .responseFormat(ResponseFormat.JSON) 401 .auth(this.auth) 402 .networkSession(this.networkSession) 403 .build()); 404 return JsonManager.deserialize(response.getData(), FileFull.class); 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( 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 = 506 prepareParams( 507 mapOf( 508 entryOf("min_height", convertToString(queryParams.getMinHeight())), 509 entryOf("min_width", convertToString(queryParams.getMinWidth())), 510 entryOf("max_height", convertToString(queryParams.getMaxHeight())), 511 entryOf("max_width", convertToString(queryParams.getMaxWidth())))); 512 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 513 FetchResponse response = 514 this.networkSession 515 .getNetworkClient() 516 .fetch( 517 new FetchOptions.Builder( 518 String.join( 519 "", 520 this.networkSession.getBaseUrls().getBaseUrl(), 521 "/2.0/files/", 522 convertToString(fileId), 523 "/thumbnail.", 524 convertToString(extension)), 525 "GET") 526 .params(queryParamsMap) 527 .headers(headersMap) 528 .responseFormat(ResponseFormat.NO_CONTENT) 529 .auth(this.auth) 530 .networkSession(this.networkSession) 531 .followRedirects(false) 532 .build()); 533 if (response.getHeaders().containsKey("location")) { 534 return response.getHeaders().get("location"); 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( 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 = 644 prepareParams( 645 mapOf( 646 entryOf("min_height", convertToString(queryParams.getMinHeight())), 647 entryOf("min_width", convertToString(queryParams.getMinWidth())), 648 entryOf("max_height", convertToString(queryParams.getMaxHeight())), 649 entryOf("max_width", convertToString(queryParams.getMaxWidth())))); 650 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 651 FetchResponse response = 652 this.networkSession 653 .getNetworkClient() 654 .fetch( 655 new FetchOptions.Builder( 656 String.join( 657 "", 658 this.networkSession.getBaseUrls().getBaseUrl(), 659 "/2.0/files/", 660 convertToString(fileId), 661 "/thumbnail.", 662 convertToString(extension)), 663 "GET") 664 .params(queryParamsMap) 665 .headers(headersMap) 666 .responseFormat(ResponseFormat.BINARY) 667 .auth(this.auth) 668 .networkSession(this.networkSession) 669 .build()); 670 if (convertToString(response.getStatus()).equals("202")) { 671 return null; 672 } 673 return response.getContent(); 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() {} 691 692 public Builder auth(Authentication auth) { 693 this.auth = auth; 694 return this; 695 } 696 697 public Builder networkSession(NetworkSession networkSession) { 698 this.networkSession = networkSession; 699 return this; 700 } 701 702 public FilesManager build() { 703 if (this.networkSession == null) { 704 this.networkSession = new NetworkSession(); 705 } 706 return new FilesManager(this); 707 } 708 } 709}