@@ -104,12 +104,20 @@ module {{ spec.title | caseUcfirst }}
104
104
on_progress: nil,
105
105
response_type: nil
106
106
)
107
- file_path = params[param_name.to_sym]
108
- size = ::File.size(file_path)
107
+ input_file = params[param_name.to_sym]
108
+
109
+ case input_file.source_type
110
+ when 'path'
111
+ size = ::File.size(input_file.path)
112
+ when 'bytes'
113
+ size = input_file.data.bytesize
114
+ end
109
115
110
116
if size < @chunk_size
111
- slice = ::File.read(file_path)
112
- params[param_name] = File.new(file_path, slice)
117
+ if input_file.source_type == 'path'
118
+ input_file.data = IO.read(input_file.path)
119
+ end
120
+ params[param_name] = input_file
113
121
return call(
114
122
method: 'POST',
115
123
path: path,
@@ -133,10 +141,16 @@ module {{ spec.title | caseUcfirst }}
133
141
offset = [size, (chunks_uploaded * @chunk_size)].min
134
142
end
135
143
136
- while offset < size
137
- slice = IO.read(file_path, @chunk_size, offset)
144
+ cached_input = input_file
138
145
139
- params[param_name] = File.new(file_path, slice)
146
+ while offset < size
147
+ case input_file.source_type
148
+ when 'path'
149
+ input_file.data = IO.read(input_file.path, @chunk_size, offset)
150
+ when 'bytes'
151
+ input_file.data = cached_input.data.slice(offset, @chunk_size)
152
+ end
153
+ params[param_name] = input_file
140
154
headers['content-range'] = "bytes #{offset}-#{[offset + @chunk_size - 1, size].min}/#{size}"
141
155
142
156
result = call(
@@ -250,10 +264,10 @@ module {{ spec.title | caseUcfirst }}
250
264
''
251
265
else
252
266
post_body = []
253
- if value.instance_of? File
254
- post_body << "Content-Disposition: form-data; name=\"#{key}\"; filename=\"#{value.name }\"\r\n"
267
+ if value.instance_of? InputFile
268
+ post_body << "Content-Disposition: form-data; name=\"#{key}\"; filename=\"#{value.filename }\"\r\n"
255
269
post_body << "Content-Type: #{value.mime_type}\r\n\r\n"
256
- post_body << value.content
270
+ post_body << value.data
257
271
post_body << "\r\n--#{@boundary}--\r\n"
258
272
else
259
273
post_body << "Content-Disposition: form-data; name=\"#{key}\"\r\n\r\n"
0 commit comments