|
28 | 28 | import org.apache.http.impl.client.HttpClients; |
29 | 29 |
|
30 | 30 | import synapticloop.b2.exception.B2ApiException; |
31 | | -import synapticloop.b2.request.B2AuthorizeAccountRequest; |
32 | | -import synapticloop.b2.request.B2CancelLargeFileRequest; |
33 | | -import synapticloop.b2.request.B2CreateBucketRequest; |
34 | | -import synapticloop.b2.request.B2DeleteBucketRequest; |
35 | | -import synapticloop.b2.request.B2DeleteFileVersionRequest; |
36 | | -import synapticloop.b2.request.B2DownloadFileByIdRequest; |
37 | | -import synapticloop.b2.request.B2DownloadFileByNameRequest; |
38 | | -import synapticloop.b2.request.B2FinishLargeFileRequest; |
39 | | -import synapticloop.b2.request.B2GetFileInfoRequest; |
40 | | -import synapticloop.b2.request.B2GetUploadPartUrlRequest; |
41 | | -import synapticloop.b2.request.B2GetUploadUrlRequest; |
42 | | -import synapticloop.b2.request.B2HeadFileByIdRequest; |
43 | | -import synapticloop.b2.request.B2HideFileRequest; |
44 | | -import synapticloop.b2.request.B2ListBucketsRequest; |
45 | | -import synapticloop.b2.request.B2ListFileNamesRequest; |
46 | | -import synapticloop.b2.request.B2ListFileVersionsRequest; |
47 | | -import synapticloop.b2.request.B2ListPartsRequest; |
48 | | -import synapticloop.b2.request.B2ListUnfinishedLargeFilesRequest; |
49 | | -import synapticloop.b2.request.B2StartLargeFileRequest; |
50 | | -import synapticloop.b2.request.B2UpdateBucketRequest; |
51 | | -import synapticloop.b2.request.B2UploadFileRequest; |
52 | | -import synapticloop.b2.request.B2UploadPartRequest; |
| 31 | +import synapticloop.b2.request.*; |
53 | 32 | import synapticloop.b2.response.B2AuthorizeAccountResponse; |
54 | 33 | import synapticloop.b2.response.B2BucketResponse; |
55 | 34 | import synapticloop.b2.response.B2DeleteFileVersionResponse; |
@@ -769,6 +748,25 @@ public B2ListFilesResponse listFileVersions(String bucketId, String startFileNam |
769 | 748 | * |
770 | 749 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
771 | 750 |
|
| 751 | + /** |
| 752 | + * Used to generate an authorization token that can be used to download files with the specified prefix |
| 753 | + * from a private B2 bucket. Returns an authorization token that can be passed to b2_download_file_by_name |
| 754 | + * in the Authorization header or as an Authorization parameter. |
| 755 | + * |
| 756 | + * @param bucketId the id of the bucket |
| 757 | + * @param fileNamePrefix The file name prefix of files the download authorization token will allow b2_download_file_by_name to access. |
| 758 | + * @param validDurationInSeconds The number of seconds before the authorization token will expire. |
| 759 | + * The maximum value is 604800 which is one week in seconds |
| 760 | + * @return The authorization token that can be passed in the Authorization header or as an Authorization |
| 761 | + * parameter to b2_download_file_by_name to access files beginning with the file name prefix. |
| 762 | + * |
| 763 | + * @throws B2ApiException if there was an error with the call |
| 764 | + * @throws IOException if there was an error communicating with the API service |
| 765 | + */ |
| 766 | + public String getDownloadAuthorization(String bucketId, String fileNamePrefix, Integer validDurationInSeconds) throws B2ApiException, IOException { |
| 767 | + return new B2GetDownloadAuthorizationRequest(client, b2AuthorizeAccountResponse, bucketId, fileNamePrefix, validDurationInSeconds).getResponse().getAuthorizationToken(); |
| 768 | + } |
| 769 | + |
772 | 770 | /** |
773 | 771 | * Download a named file from a named bucket to an output file. This is a |
774 | 772 | * utility method which will automatically write the content to the file. |
|
0 commit comments