Package dev.dosya.sdk.resource
Class DownloadResource
java.lang.Object
dev.dosya.sdk.resource.DownloadResource
Provides operations for downloading files from Dosya.
Supports retrieving download URLs, downloading file content as byte arrays,
and streaming file content via InputStream.
- Since:
- 0.1.0
-
Constructor Summary
ConstructorsConstructorDescriptionDownloadResource(@NotNull DosyaHttpClient http) Creates a newDownloadResourcebacked by the given HTTP client. -
Method Summary
Modifier and TypeMethodDescriptionbyte @NotNull []downloadBytes(@NotNull String fileId) Downloads the latest version of a file as a byte array.byte @NotNull []downloadBytes(@NotNull String fileId, @Nullable Integer version, @Nullable String unlockToken) Downloads the file content as a byte array.@NotNull InputStreamdownloadStream(@NotNull String fileId) Downloads the latest version of a file as a streamingInputStream.@NotNull InputStreamdownloadStream(@NotNull String fileId, @Nullable Integer version, @Nullable String unlockToken) Downloads the file content as a streamingInputStream.@NotNull StringRetrieves a pre-signed download URL for the latest version of a file.@NotNull StringRetrieves a pre-signed download URL for a file.
-
Constructor Details
-
DownloadResource
Creates a newDownloadResourcebacked by the given HTTP client.- Parameters:
http- the HTTP client used to make API requests
-
-
Method Details
-
getUrl
@NotNull public @NotNull String getUrl(@NotNull @NotNull String fileId, @Nullable @Nullable Integer version, @Nullable @Nullable String unlockToken) Retrieves a pre-signed download URL for a file.- Parameters:
fileId- the unique identifier of the fileversion- the file version number, ornullfor the latest versionunlockToken- the unlock token for locked files, ornullif not locked- Returns:
- the pre-signed download URL
- Throws:
DosyaException- if the download URL cannot be extracted from the responseDosyaApiException- if the API returns an error
-
getUrl
Retrieves a pre-signed download URL for the latest version of a file.- Parameters:
fileId- the unique identifier of the file- Returns:
- the pre-signed download URL
- Throws:
DosyaException- if the download URL cannot be extracted from the responseDosyaApiException- if the API returns an error
-
downloadBytes
public byte @NotNull [] downloadBytes(@NotNull @NotNull String fileId, @Nullable @Nullable Integer version, @Nullable @Nullable String unlockToken) Downloads the file content as a byte array.- Parameters:
fileId- the unique identifier of the fileversion- the file version number, ornullfor the latest versionunlockToken- the unlock token for locked files, ornullif not locked- Returns:
- the file content as a byte array
- Throws:
DosyaException- if the download failsDosyaApiException- if the API returns an error
-
downloadBytes
Downloads the latest version of a file as a byte array.- Parameters:
fileId- the unique identifier of the file- Returns:
- the file content as a byte array
- Throws:
DosyaException- if the download failsDosyaApiException- if the API returns an error
-
downloadStream
@NotNull public @NotNull InputStream downloadStream(@NotNull @NotNull String fileId, @Nullable @Nullable Integer version, @Nullable @Nullable String unlockToken) Downloads the file content as a streamingInputStream.The caller is responsible for closing the returned stream, which will also disconnect the underlying HTTP connection.
- Parameters:
fileId- the unique identifier of the fileversion- the file version number, ornullfor the latest versionunlockToken- the unlock token for locked files, ornullif not locked- Returns:
- an input stream of the file content
- Throws:
DosyaException- if the download failsDosyaApiException- if the API returns an error
-
downloadStream
Downloads the latest version of a file as a streamingInputStream.The caller is responsible for closing the returned stream.
- Parameters:
fileId- the unique identifier of the file- Returns:
- an input stream of the file content
- Throws:
DosyaException- if the download failsDosyaApiException- if the API returns an error
-