@@ -42,6 +42,7 @@ def upload(file:, request_options: {}, **options, &block)
4242 file_size = prepared_file . size
4343 filename = prepared_file . original_filename
4444 content_type = MIME ::Types . type_for ( prepared_file . path ) . first &.content_type || 'application/octet-stream'
45+ part_size , threads = normalize_upload_options ( options )
4546
4647 start_response = Uploadcare ::Result . unwrap (
4748 upload_client . files . multipart_start (
@@ -56,9 +57,6 @@ def upload(file:, request_options: {}, **options, &block)
5657 uuid = start_response [ 'uuid' ]
5758 presigned_urls = start_response [ 'parts' ]
5859
59- part_size = options . fetch ( :part_size , config . multipart_chunk_size )
60- threads = options . fetch ( :threads , 1 )
61-
6260 if threads > 1
6361 upload_parts_parallel ( prepared_file , presigned_urls , part_size , threads , &block )
6462 else
@@ -77,6 +75,16 @@ def upload(file:, request_options: {}, **options, &block)
7775
7876 private
7977
78+ def normalize_upload_options ( options )
79+ part_size = Integer ( options . fetch ( :part_size , config . multipart_chunk_size || CHUNK_SIZE ) )
80+ threads = Integer ( options . fetch ( :threads , 1 ) )
81+
82+ raise ArgumentError , 'part_size must be > 0' if part_size <= 0
83+ raise ArgumentError , 'threads must be >= 1' if threads < 1
84+
85+ [ part_size , threads ]
86+ end
87+
8088 def upload_parts_sequential ( file , presigned_urls , part_size , &block )
8189 total_size = file . respond_to? ( :size ) ? file . size : ::File . size ( file . path )
8290 uploaded = 0
0 commit comments