class ActiveStorage::Service::S3Service

def compose(source_keys, destination_key, filename: nil, content_type: nil, disposition: nil, custom_metadata: {})

def compose(source_keys, destination_key, filename: nil, content_type: nil, disposition: nil, custom_metadata: {})
  content_disposition = content_disposition_with(type: disposition, filename: filename) if disposition && filename
  object_for(destination_key).upload_stream(
    content_type: content_type,
    content_disposition: content_disposition,
    part_size: MINIMUM_UPLOAD_PART_SIZE,
    metadata: custom_metadata,
    **upload_options
  ) do |out|
    source_keys.each do |source_key|
      stream(source_key) do |chunk|
        IO.copy_stream(StringIO.new(chunk), out)
      end
    end
  end
end