Class InputStreamUploadRequest

java.lang.Object
io.micronaut.objectstorage.request.AbstractUploadRequest
io.micronaut.objectstorage.request.InputStreamUploadRequest
All Implemented Interfaces:
UploadRequest

public class InputStreamUploadRequest extends AbstractUploadRequest
An UploadRequest backed by an InputStream.

The request returns the same stream instance and does not copy or buffer its contents. Callers must not access the stream while an upload is in progress. Provider implementations may close the stream, so callers that own it should ensure it is closed after a blocking upload returns or after a reactive upload terminates.

Because the stream is not recreated, automatic retries may require a stream that supports InputStream.mark(int) and InputStream.reset(). A non-repeatable stream may fail if a provider retries after consuming part of it. Providing the content length allows providers to stream the request without buffering and is required by some provider operations.

Since:
3.1.0
  • Constructor Details

    • InputStreamUploadRequest

      public InputStreamUploadRequest(@NonNull InputStream inputStream, @NonNull String key)
      Creates a request with an unknown content length and a content type inferred from the key.
      Parameters:
      inputStream - the source input stream.
      key - the key under which the object will be stored.
      Since:
      3.1.0
    • InputStreamUploadRequest

      public InputStreamUploadRequest(@NonNull InputStream inputStream, @NonNull String key, long contentLength)
      Creates a request with a known content length and a content type inferred from the key.
      Parameters:
      inputStream - the source input stream.
      key - the key under which the object will be stored.
      contentLength - the number of bytes to read from the stream.
      Since:
      3.1.0
    • InputStreamUploadRequest

      public InputStreamUploadRequest(@NonNull InputStream inputStream, @NonNull String key, @Nullable String contentType, @Nullable Long contentLength)
      Creates a request with optional content type and content length.
      Parameters:
      inputStream - the source input stream.
      key - the key under which the object will be stored.
      contentType - the content type, or null when unknown.
      contentLength - the number of bytes to read from the stream, or null when unknown.
      Since:
      3.1.0
    • InputStreamUploadRequest

      public InputStreamUploadRequest(@NonNull InputStream inputStream, @NonNull String key, @Nullable String contentType, @Nullable Long contentLength, @NonNull Map<String,String> metadata)
      Creates a request with optional content type, optional content length, and metadata.
      Parameters:
      inputStream - the source input stream.
      key - the key under which the object will be stored.
      contentType - the content type, or null when unknown.
      contentLength - the number of bytes to read from the stream, or null when unknown.
      metadata - key-value pairs to store with the object.
      Since:
      3.1.0
  • Method Details

    • getContentType

      public @NonNull Optional<String> getContentType()
      Returns:
      the content type of this upload request.
    • getKey

      public @NonNull String getKey()
      Returns:
      the file name with path.
    • getContentSize

      public @NonNull Optional<Long> getContentSize()
      Returns:
      the size of the file, in bytes.
    • getInputStream

      public @NonNull InputStream getInputStream()
      Returns an input stream of the object to be stored.

      Callers must not access the stream while an upload is in progress. Provider implementations may close it, so callers that own the stream should ensure it is closed after a blocking upload returns or after a reactive upload terminates.

      Returns:
      an input stream of the object to be stored.