@@ -100,6 +100,7 @@ module {{ spec.title | caseUcfirst }}
100
100
headers:,
101
101
params:,
102
102
param_name: '',
103
+ id_param_name: nil,
103
104
on_progress: nil,
104
105
response_type: nil
105
106
)
@@ -118,11 +119,22 @@ module {{ spec.title | caseUcfirst }}
118
119
)
119
120
end
120
121
121
- input = ::File.open(file_path)
122
122
offset = 0
123
+ id_param_name = id_param_name.to_sym if id_param_name
124
+ if id_param_name& .empty? == false && params[id_param_name] != "unique()"
125
+ # Make a request to check if a file already exists
126
+ current = call(
127
+ method: "GET",
128
+ path: "#{path}/#{params[id_param_name]}",
129
+ headers: headers,
130
+ params: {}
131
+ )
132
+ chunks_uploaded = current['chunksUploaded'].to_i
133
+ offset = [size, (chunks_uploaded * @chunk_size)].min
134
+ end
123
135
124
136
while offset < size
125
- slice = input .read(@chunk_size)
137
+ slice = IO .read(file_path, @chunk_size, offset )
126
138
127
139
params[param_name] = File.new(file_path, slice)
128
140
headers['content-range'] = "bytes #{offset}-#{[offset + @chunk_size - 1, size].min}/#{size}"
@@ -144,8 +156,8 @@ module {{ spec.title | caseUcfirst }}
144
156
id: result['$id'],
145
157
progress: ([offset, size].min).to_f/size.to_f * 100.0,
146
158
size_uploaded: [offset, size].min,
147
- chunks_total: result['chunks_total '],
148
- chunks_uploaded: result['chunks_uploaded ']
159
+ chunks_total: result['chunksTotal '],
160
+ chunks_uploaded: result['chunksUploaded ']
149
161
}) unless on_progress.nil?
150
162
end
151
163
0 commit comments