Class UploadResource

java.lang.Object
dev.dosya.sdk.resource.UploadResource

public final class UploadResource extends Object
Provides operations for uploading files to Dosya workspaces.

Supports single-part and multipart uploads with automatic concurrency, progress tracking, and resumable upload sessions.

Since:
0.1.0
  • Constructor Details

    • UploadResource

      public UploadResource(@NotNull @NotNull DosyaHttpClient http)
      Creates a new UploadResource backed by the given HTTP client.
      Parameters:
      http - the HTTP client used to make API requests
  • Method Details

    • file

      @NotNull public @NotNull UploadResult file(@NotNull @NotNull UploadParams params)
      Uploads a file using the provided parameters. Automatically selects single-part or multipart upload based on the server response.
      Parameters:
      params - the upload parameters including workspace ID, file data, and optional settings
      Returns:
      the upload result containing the uploaded file detail and session ID
      Throws:
      DosyaUploadException - if the upload fails
      DosyaApiException - if the API returns an error
    • resume

      @NotNull public @NotNull UploadResult resume(@NotNull @NotNull String sessionId, @NotNull @org.jetbrains.annotations.NotNull byte[] body, @Nullable @Nullable Consumer<UploadProgress> onProgress)
      Resumes a previously started multipart upload session.
      Parameters:
      sessionId - the upload session ID to resume
      body - the full file bytes to upload
      onProgress - an optional callback for progress updates, or null
      Returns:
      the upload result containing the uploaded file detail and session ID
      Throws:
      DosyaUploadException - if the session is already complete, not multipart, or the upload fails
      DosyaApiException - if the API returns an error
    • init

      @NotNull public @NotNull UploadInitResponse init(@NotNull @NotNull String workspaceId, @NotNull @NotNull String fileName, long fileSize, @Nullable @Nullable String mimeType, @Nullable @Nullable String region, @Nullable @Nullable String folderId, @Nullable @Nullable String fileId)
      Initializes an upload session with the Dosya API.
      Parameters:
      workspaceId - the workspace to upload into
      fileName - the name of the file being uploaded
      fileSize - the total file size in bytes
      mimeType - the MIME type of the file, or null for auto-detection
      region - the storage region, or null for the default
      folderId - the target folder ID, or null for the workspace root
      fileId - an existing file ID for versioned re-upload, or null
      Returns:
      the initialization response containing session ID and upload instructions
      Throws:
      DosyaApiException - if the API returns an error
    • status

      @NotNull public @NotNull UploadStatusResponse status(@NotNull @NotNull String sessionId)
      Retrieves the current status of an upload session.
      Parameters:
      sessionId - the upload session ID
      Returns:
      the status response including uploaded parts and progress
      Throws:
      DosyaApiException - if the API returns an error