filestack 2.6.7 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +3 -0
- data/README.md +19 -10
- data/VERSION +1 -1
- data/lib/filestack/config.rb +19 -6
- data/lib/filestack/models/filestack_client.rb +8 -15
- data/lib/filestack/ruby/version.rb +1 -1
- data/lib/filestack/utils/multipart_upload_utils.rb +31 -49
- data/lib/filestack/utils/utils.rb +50 -39
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 36cd3251f64e64ffcdb9d42c73cbf6d49bcda8a2533cb8053e0087229a077bf2
|
4
|
+
data.tar.gz: f2e38e698557c0b336c332be5b68775fe2624e046a56e1c521717554f23b6495
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26a1b21b1ad69ae42708e94323e28d7656881824e668677b0dc27a4bb13a035ed6f5b104f90615a0e53bf3b454621fa3a3e129a6a412eed15dd7271f33100f84
|
7
|
+
data.tar.gz: 4d2c6c3e96da48df28e067f6990e3313669ffb2cf0f33f62964db5f708b42b0818c9992cec713c0b70acc6db72425bb727545726a1757c9c64c9dc7addcf6090
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -44,41 +44,50 @@ Or install it yourself as:
|
|
44
44
|
require 'filestack'
|
45
45
|
```
|
46
46
|
Intialize the client using your API key, and security if you are using it.
|
47
|
+
|
47
48
|
```ruby
|
48
49
|
client = FilestackClient.new('YOUR_API_KEY', security: security_object)
|
49
50
|
```
|
50
51
|
### Uploading
|
51
|
-
Filestack uses multipart uploading by default, which is faster for larger files. This can be turned off by passing in ```multipart: false```. Multipart is disabled when uploading external URLs.
|
52
52
|
```ruby
|
53
|
-
filelink = client.upload(filepath: '/path/to/
|
54
|
-
|
55
|
-
filelink = client.upload(filepath: '/path/to/file', multipart: false)
|
53
|
+
filelink = client.upload(filepath: '/path/to/localfile')
|
56
54
|
|
57
55
|
# OR
|
58
56
|
|
59
|
-
filelink = client.upload(external_url: 'http://
|
57
|
+
filelink = client.upload(external_url: 'http://domain.com/image.png')
|
60
58
|
```
|
61
59
|
|
62
60
|
To upload a local and an external file with query parameters:
|
63
61
|
```ruby
|
64
|
-
filelink = client.upload(filepath: '/path/to/
|
62
|
+
filelink = client.upload(filepath: '/path/to/localfile', options: { mimetype: 'image/png' })
|
65
63
|
|
66
|
-
filelink = client.upload(external_url: 'http://
|
64
|
+
filelink = client.upload(external_url: 'http://domain.com/image.png', options: { mimetype: 'image/jpeg' })
|
67
65
|
```
|
68
66
|
|
69
67
|
To store file on `dropbox`, `azure`, `gcs` or `rackspace`, you must have the chosen provider configured in the developer portal to enable this feature. By default the file is stored on `s3`. You can add more details of the storage in `options`.
|
70
68
|
|
71
69
|
```ruby
|
72
|
-
filelink = client.upload(filepath: '/path/to/file', storage: '
|
70
|
+
filelink = client.upload(filepath: '/path/to/file', storage: 's3', options: { path: 'folder_name/', container: 'container_name', location: 's3', region: 'region_name' })
|
71
|
+
|
72
|
+
filelink = client.upload(external_url: 'http://someurl.com/image.png', options: { location: 'dropbox', path: 'folder_name' })
|
73
|
+
```
|
74
|
+
|
75
|
+
### Workflows
|
76
|
+
Workflows allow you to wire up conditional logic and image processing to enforce business processes, automate ingest, and save valuable development time. In order to trigger the workflow job for each upload:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
filelink = client.upload(filepath: '/path/to/file', options: { workflows: ["workflow_id_1", "workflow_id_2"] })
|
80
|
+
|
81
|
+
#OR
|
73
82
|
|
74
|
-
filelink = client.upload(external_url: 'http://someurl.com/image.png',
|
83
|
+
filelink = client.upload(external_url: 'http://someurl.com/image.png', options: { workflows: ["workflow_id_1"] })
|
75
84
|
```
|
76
85
|
|
77
86
|
### Security
|
78
87
|
If security is enabled on your account, or if you are using certain actions that require security (delete, overwrite and certain transformations), you will need to create a security object and pass it into the client on instantiation.
|
79
88
|
|
80
89
|
```ruby
|
81
|
-
security = FilestackSecurity.new('YOUR_APP_SECRET', options: {call: %w[read store pick]})
|
90
|
+
security = FilestackSecurity.new('YOUR_APP_SECRET', options: {call: %w[read store pick runWorkflow]})
|
82
91
|
client = FilestackClient.new('YOUR_API_KEY', security: security)
|
83
92
|
```
|
84
93
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.7.0
|
data/lib/filestack/config.rb
CHANGED
@@ -7,11 +7,6 @@ class FilestackConfig
|
|
7
7
|
CDN_URL = 'https://cdn.filestackcontent.com'.freeze
|
8
8
|
PROCESS_URL = 'https://process.filestackapi.com'.freeze
|
9
9
|
|
10
|
-
MULTIPART_START_URL = 'https://upload.filestackapi.com/multipart/start'.freeze
|
11
|
-
MULTIPART_UPLOAD_URL = 'https://upload.filestackapi.com/multipart/upload'.freeze
|
12
|
-
MULTIPART_COMMIT_URL = 'https://upload.filestackapi.com/multipart/commit'.freeze
|
13
|
-
MULTIPART_COMPLETE_URL = 'https://upload.filestackapi.com/multipart/complete'.freeze
|
14
|
-
|
15
10
|
MULTIPART_PARAMS = %w[
|
16
11
|
store_location store_region store_container
|
17
12
|
store_path store_access
|
@@ -22,10 +17,28 @@ class FilestackConfig
|
|
22
17
|
VERSION = Filestack::Ruby::VERSION
|
23
18
|
HEADERS = {
|
24
19
|
'User-Agent' => "filestack-ruby #{VERSION}",
|
25
|
-
'Filestack-Source' => "Ruby-#{VERSION}"
|
20
|
+
'Filestack-Source' => "Ruby-#{VERSION}",
|
21
|
+
'Content-Type' => "application/json",
|
22
|
+
'Accept-Encoding' => "application/json"
|
26
23
|
}.freeze
|
27
24
|
|
28
25
|
INTELLIGENT_ERROR_MESSAGES = ['BACKEND_SERVER', 'BACKEND_NETWORK', 'S3_SERVER', 'S3_NETWORK']
|
26
|
+
|
27
|
+
def self.multipart_start_url
|
28
|
+
"https://upload.filestackapi.com/multipart/start"
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.multipart_upload_url(base_url)
|
32
|
+
"https://#{base_url}/multipart/upload"
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.multipart_commit_url(base_url)
|
36
|
+
"https://#{base_url}/multipart/commit"
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.multipart_complete_url(base_url)
|
40
|
+
"https://#{base_url}/multipart/complete"
|
41
|
+
end
|
29
42
|
end
|
30
43
|
|
31
44
|
class TransformConfig
|
@@ -26,26 +26,19 @@ class FilestackClient
|
|
26
26
|
# Upload a local file or external url
|
27
27
|
# @param [String] filepath The path of a local file
|
28
28
|
# @param [String] external_url An external URL
|
29
|
-
# @param [Bool] multipart Switch for miltipart
|
30
|
-
# (Default: true)
|
31
29
|
# @param [Hash] options User-supplied upload options
|
32
30
|
#
|
33
31
|
# return [Filestack::FilestackFilelink]
|
34
|
-
def upload(filepath: nil, external_url: nil,
|
35
|
-
if filepath && external_url
|
36
|
-
|
37
|
-
|
38
|
-
response = if filepath && multipart
|
32
|
+
def upload(filepath: nil, external_url: nil, options: {}, intelligent: false, timeout: 60, storage: 'S3')
|
33
|
+
return 'You cannot upload a URL and file at the same time' if filepath && external_url
|
34
|
+
|
35
|
+
response = if filepath
|
39
36
|
multipart_upload(@apikey, filepath, @security, options, timeout, storage, intelligent: intelligent)
|
40
37
|
else
|
41
|
-
send_upload(
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
options: options,
|
46
|
-
security: @security,
|
47
|
-
storage: storage
|
48
|
-
)
|
38
|
+
send_upload(@apikey,
|
39
|
+
external_url: external_url,
|
40
|
+
options: options,
|
41
|
+
security: @security)
|
49
42
|
end
|
50
43
|
FilestackFilelink.new(response['handle'], security: @security, apikey: @apikey)
|
51
44
|
end
|
@@ -23,16 +23,6 @@ module MultipartUploadUtils
|
|
23
23
|
[filename, filesize, mimetype.to_s]
|
24
24
|
end
|
25
25
|
|
26
|
-
def multipart_options(options)
|
27
|
-
[:region, :container, :path, :access].each do |key|
|
28
|
-
if options.has_key?(key)
|
29
|
-
options[:"store_#{key}"] = options[key]
|
30
|
-
options.delete(key)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
return options
|
34
|
-
end
|
35
|
-
|
36
26
|
# Send start response to multipart endpoint
|
37
27
|
#
|
38
28
|
# @param [String] apikey Filestack API key
|
@@ -51,23 +41,21 @@ module MultipartUploadUtils
|
|
51
41
|
filename: filename,
|
52
42
|
mimetype: mimetype,
|
53
43
|
size: filesize,
|
54
|
-
|
55
|
-
|
56
|
-
multipart: intelligent
|
44
|
+
store: { location: storage },
|
45
|
+
fii: intelligent
|
57
46
|
}
|
58
47
|
|
59
|
-
options
|
60
|
-
params = params.merge!(options) if options
|
48
|
+
params[:store].merge!(options) if options
|
61
49
|
|
62
50
|
unless security.nil?
|
63
51
|
params[:policy] = security.policy
|
64
52
|
params[:signature] = security.signature
|
65
53
|
end
|
66
54
|
|
67
|
-
response = Typhoeus.post(
|
68
|
-
|
69
|
-
|
70
|
-
|
55
|
+
response = Typhoeus.post(FilestackConfig.multipart_start_url,
|
56
|
+
body: params.to_json,
|
57
|
+
headers: FilestackConfig::HEADERS)
|
58
|
+
|
71
59
|
if response.code == 200
|
72
60
|
JSON.parse(response.body)
|
73
61
|
else
|
@@ -93,7 +81,7 @@ module MultipartUploadUtils
|
|
93
81
|
seek_point = 0
|
94
82
|
while seek_point < filesize
|
95
83
|
part_info = {
|
96
|
-
|
84
|
+
seek_point: seek_point,
|
97
85
|
filepath: filepath,
|
98
86
|
filename: filename,
|
99
87
|
apikey: apikey,
|
@@ -104,10 +92,10 @@ module MultipartUploadUtils
|
|
104
92
|
upload_id: start_response['upload_id'],
|
105
93
|
location_url: start_response['location_url'],
|
106
94
|
start_response: start_response,
|
107
|
-
|
95
|
+
store: { location: storage }
|
108
96
|
}
|
109
|
-
|
110
|
-
part_info
|
97
|
+
|
98
|
+
part_info[:store].merge!(options) if options
|
111
99
|
|
112
100
|
if seek_point + FilestackConfig::DEFAULT_CHUNK_SIZE > filesize
|
113
101
|
size = filesize - (seek_point)
|
@@ -135,9 +123,9 @@ module MultipartUploadUtils
|
|
135
123
|
# multipart uploads
|
136
124
|
#
|
137
125
|
# @return [Typhoeus::Response]
|
138
|
-
def upload_chunk(job, apikey, filepath, options)
|
126
|
+
def upload_chunk(job, apikey, filepath, options, storage)
|
139
127
|
file = File.open(filepath)
|
140
|
-
file.seek(job[:
|
128
|
+
file.seek(job[:seek_point])
|
141
129
|
chunk = file.read(FilestackConfig::DEFAULT_CHUNK_SIZE)
|
142
130
|
|
143
131
|
md5 = Digest::MD5.new
|
@@ -150,14 +138,14 @@ module MultipartUploadUtils
|
|
150
138
|
uri: job[:uri],
|
151
139
|
region: job[:region],
|
152
140
|
upload_id: job[:upload_id],
|
153
|
-
|
141
|
+
store: { location: storage },
|
154
142
|
file: Tempfile.new(job[:filename])
|
155
143
|
}
|
156
144
|
data = data.merge!(options) if options
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
145
|
+
|
146
|
+
fs_response = Typhoeus.post(FilestackConfig.multipart_upload_url(job[:location_url]),
|
147
|
+
body: data.to_json,
|
148
|
+
headers: FilestackConfig::HEADERS).body
|
161
149
|
fs_response = JSON.parse(fs_response)
|
162
150
|
Typhoeus.put(
|
163
151
|
fs_response['url'], headers: fs_response['headers'], body: chunk
|
@@ -172,17 +160,17 @@ module MultipartUploadUtils
|
|
172
160
|
# multipart uploads
|
173
161
|
#
|
174
162
|
# @return [Array] Array of parts/etags strings
|
175
|
-
def run_uploads(jobs, apikey, filepath, options)
|
163
|
+
def run_uploads(jobs, apikey, filepath, options, storage)
|
176
164
|
bar = ProgressBar.new(jobs.length)
|
177
165
|
results = Parallel.map(jobs, in_threads: 4) do |job|
|
178
166
|
response = upload_chunk(
|
179
|
-
job, apikey, filepath, options
|
167
|
+
job, apikey, filepath, options, storage
|
180
168
|
)
|
181
169
|
if response.code == 200
|
182
170
|
bar.increment!
|
183
171
|
part = job[:part]
|
184
172
|
etag = response.headers[:etag]
|
185
|
-
|
173
|
+
{ part_number: part, etag: etag }
|
186
174
|
end
|
187
175
|
end
|
188
176
|
results
|
@@ -213,17 +201,14 @@ module MultipartUploadUtils
|
|
213
201
|
filename: filename,
|
214
202
|
size: filesize,
|
215
203
|
mimetype: mimetype,
|
216
|
-
|
217
|
-
file: Tempfile.new(filename)
|
204
|
+
store: { location: storage },
|
218
205
|
}
|
219
|
-
options
|
220
|
-
data.merge!(
|
221
|
-
data.merge!(intelligent ? { multipart: intelligent } : { parts: parts_and_etags.join(';') })
|
206
|
+
data[:store].merge!(options) if options
|
207
|
+
data.merge!(intelligent ? { fii: intelligent } : { parts: parts_and_etags })
|
222
208
|
|
223
|
-
Typhoeus.post(
|
224
|
-
|
225
|
-
|
226
|
-
)
|
209
|
+
Typhoeus.post(FilestackConfig.multipart_complete_url(start_response['location_url']),
|
210
|
+
body: data.to_json,
|
211
|
+
headers: FilestackConfig::HEADERS)
|
227
212
|
end
|
228
213
|
|
229
214
|
# Run entire multipart process through with file and options
|
@@ -238,27 +223,24 @@ module MultipartUploadUtils
|
|
238
223
|
# @return [Hash]
|
239
224
|
def multipart_upload(apikey, filepath, security, options, timeout, storage, intelligent: false)
|
240
225
|
filename, filesize, mimetype = get_file_info(filepath)
|
226
|
+
|
241
227
|
start_response = multipart_start(
|
242
228
|
apikey, filename, filesize, mimetype, security, storage, options, intelligent
|
243
229
|
)
|
244
230
|
|
245
|
-
unless start_response['upload_type'].nil?
|
246
|
-
intelligent_enabled = ((start_response['upload_type'].include? 'intelligent_ingestion')) && intelligent
|
247
|
-
end
|
248
|
-
|
249
231
|
jobs = create_upload_jobs(
|
250
232
|
apikey, filename, filepath, filesize, start_response, storage, options
|
251
233
|
)
|
252
234
|
|
253
|
-
if
|
235
|
+
if intelligent
|
254
236
|
state = IntelligentState.new
|
255
|
-
run_intelligent_upload_flow(jobs, state)
|
237
|
+
run_intelligent_upload_flow(jobs, state, storage)
|
256
238
|
response_complete = multipart_complete(
|
257
239
|
apikey, filename, filesize, mimetype,
|
258
240
|
start_response, nil, options, storage, intelligent
|
259
241
|
)
|
260
242
|
else
|
261
|
-
parts_and_etags = run_uploads(jobs, apikey, filepath, options)
|
243
|
+
parts_and_etags = run_uploads(jobs, apikey, filepath, options, storage)
|
262
244
|
response_complete = multipart_complete(
|
263
245
|
apikey, filename, filesize, mimetype,
|
264
246
|
start_response, parts_and_etags, options, storage
|
@@ -62,36 +62,42 @@ module UploadUtils
|
|
62
62
|
)
|
63
63
|
end
|
64
64
|
|
65
|
+
def build_store_task(options = {})
|
66
|
+
return 'store' if options.empty?
|
67
|
+
tasks = []
|
68
|
+
options.each do |key, value|
|
69
|
+
value = case key
|
70
|
+
when :workflows
|
71
|
+
[value.join('","')]
|
72
|
+
when :path
|
73
|
+
"\"#{value}\""
|
74
|
+
else
|
75
|
+
value
|
76
|
+
end
|
77
|
+
tasks.push("#{key}:#{value.to_s.downcase}")
|
78
|
+
end
|
79
|
+
"store=#{tasks.join(',')}"
|
80
|
+
end
|
81
|
+
|
65
82
|
# Uploads to v1 REST API (for external URLs or if multipart is turned off)
|
66
83
|
#
|
67
84
|
# @param [String] apikey Filestack API key
|
68
|
-
# @param [String] filepath Local path to file
|
69
85
|
# @param [String] external_url External URL to be uploaded
|
70
86
|
# @param [FilestackSecurity] security Security object with
|
71
87
|
# policy/signature
|
72
88
|
# @param [Hash] options User-defined options for
|
73
89
|
# multipart uploads
|
74
|
-
# @param [String] storage Storage destination
|
75
|
-
# (s3, rackspace, etc)
|
76
90
|
# @return [Hash]
|
77
|
-
def send_upload(apikey,
|
78
|
-
|
79
|
-
{ fileUpload: File.open(filepath) }
|
80
|
-
else
|
81
|
-
{ url: external_url }
|
82
|
-
end
|
83
|
-
|
84
|
-
# adds any user-defined upload options to request payload
|
85
|
-
data = data.merge!(options) unless options.nil?
|
86
|
-
base = "#{FilestackConfig::API_URL}/store/#{storage}?key=#{apikey}"
|
91
|
+
def send_upload(apikey, external_url: nil, security: nil, options: nil)
|
92
|
+
base = "#{FilestackConfig::CDN_URL}/#{apikey}/#{build_store_task(options)}"
|
87
93
|
|
88
94
|
if security
|
89
95
|
policy = security.policy
|
90
96
|
signature = security.signature
|
91
|
-
base = "#{base}
|
97
|
+
base = "#{base}/security=s:#{signature},p:#{policy}"
|
92
98
|
end
|
93
99
|
|
94
|
-
response = Typhoeus.post(base,
|
100
|
+
response = Typhoeus.post("#{base}/#{external_url}", headers: FilestackConfig::HEADERS)
|
95
101
|
|
96
102
|
if response.code == 200
|
97
103
|
response_body = JSON.parse(response.body)
|
@@ -193,7 +199,7 @@ module IntelligentUtils
|
|
193
199
|
# @param [IntelligentState] state An IntelligentState object
|
194
200
|
#
|
195
201
|
# @return [Array]
|
196
|
-
def run_intelligent_upload_flow(jobs, state)
|
202
|
+
def run_intelligent_upload_flow(jobs, state, storage)
|
197
203
|
bar = ProgressBar.new(jobs.length)
|
198
204
|
generator = create_intelligent_generator(jobs)
|
199
205
|
working_offset = FilestackConfig::DEFAULT_OFFSET_SIZE
|
@@ -201,7 +207,7 @@ module IntelligentUtils
|
|
201
207
|
batch = get_generator_batch(generator)
|
202
208
|
# run parts
|
203
209
|
Parallel.map(batch, in_threads: 4) do |part|
|
204
|
-
state = run_intelligent_uploads(part, state)
|
210
|
+
state = run_intelligent_uploads(part, state, storage)
|
205
211
|
# condition: a chunk has failed but we have not reached the maximum retries
|
206
212
|
while bad_state(state)
|
207
213
|
# condition: timeout to S3, requiring offset size to be changed
|
@@ -213,7 +219,7 @@ module IntelligentUtils
|
|
213
219
|
sleep(state.backoff)
|
214
220
|
end
|
215
221
|
state.add_retry
|
216
|
-
state = run_intelligent_uploads(part, state)
|
222
|
+
state = run_intelligent_uploads(part, state, storage)
|
217
223
|
end
|
218
224
|
raise "Upload has failed. Please try again later." unless state.ok
|
219
225
|
bar.increment!
|
@@ -269,13 +275,14 @@ module IntelligentUtils
|
|
269
275
|
# multipart_start
|
270
276
|
#
|
271
277
|
# @return [Dict]
|
272
|
-
def chunk_job(job, state, apikey, filename, filepath, filesize, start_response)
|
278
|
+
def chunk_job(job, state, apikey, filename, filepath, filesize, start_response, storage)
|
273
279
|
offset = 0
|
274
|
-
seek_point = job[:
|
280
|
+
seek_point = job[:seek_point]
|
275
281
|
chunk_list = []
|
282
|
+
|
276
283
|
while (offset < FilestackConfig::DEFAULT_CHUNK_SIZE) && (seek_point + offset) < filesize
|
277
284
|
chunk_list.push(
|
278
|
-
|
285
|
+
seek_point: seek_point,
|
279
286
|
filepath: filepath,
|
280
287
|
filename: filename,
|
281
288
|
apikey: apikey,
|
@@ -285,7 +292,7 @@ module IntelligentUtils
|
|
285
292
|
region: start_response['region'],
|
286
293
|
upload_id: start_response['upload_id'],
|
287
294
|
location_url: start_response['location_url'],
|
288
|
-
|
295
|
+
store: { location: storage },
|
289
296
|
offset: offset
|
290
297
|
)
|
291
298
|
offset += state.offset
|
@@ -300,15 +307,15 @@ module IntelligentUtils
|
|
300
307
|
# @param [IntelligentState] state An IntelligentState object
|
301
308
|
#
|
302
309
|
# @return [IntelligentState]
|
303
|
-
def run_intelligent_uploads(part, state)
|
310
|
+
def run_intelligent_uploads(part, state, storage)
|
304
311
|
failed = false
|
305
312
|
chunks = chunk_job(
|
306
313
|
part, state, part[:apikey], part[:filename], part[:filepath],
|
307
|
-
part[:filesize], part[:start_response]
|
314
|
+
part[:filesize], part[:start_response], storage
|
308
315
|
)
|
309
316
|
Parallel.map(chunks, in_threads: 3) do |chunk|
|
310
317
|
begin
|
311
|
-
upload_chunk_intelligently(chunk, state, part[:apikey], part[:filepath], part[:options])
|
318
|
+
upload_chunk_intelligently(chunk, state, part[:apikey], part[:filepath], part[:options], storage)
|
312
319
|
rescue => e
|
313
320
|
state.error_type = e.message
|
314
321
|
failed = true
|
@@ -322,6 +329,7 @@ module IntelligentUtils
|
|
322
329
|
else
|
323
330
|
state.ok = true
|
324
331
|
end
|
332
|
+
|
325
333
|
commit_params = {
|
326
334
|
apikey: part[:apikey],
|
327
335
|
uri: part[:uri],
|
@@ -329,12 +337,14 @@ module IntelligentUtils
|
|
329
337
|
upload_id: part[:upload_id],
|
330
338
|
size: part[:filesize],
|
331
339
|
part: part[:part],
|
332
|
-
location_url: part[:location_url],
|
333
|
-
|
334
|
-
file: Tempfile.new(part[:filename])
|
340
|
+
location_url: part[:start_response]['location_url'],
|
341
|
+
store: { location: storage }
|
335
342
|
}
|
336
|
-
|
337
|
-
|
343
|
+
|
344
|
+
response = Typhoeus.post(FilestackConfig.multipart_commit_url(commit_params[:location_url]),
|
345
|
+
body: commit_params.to_json,
|
346
|
+
headers: FilestackConfig::HEADERS)
|
347
|
+
|
338
348
|
if response.code == 200
|
339
349
|
state.reset
|
340
350
|
else
|
@@ -354,9 +364,10 @@ module IntelligentUtils
|
|
354
364
|
# multipart uploads
|
355
365
|
#
|
356
366
|
# @return [Typhoeus::Response]
|
357
|
-
def upload_chunk_intelligently(job, state, apikey, filepath, options)
|
367
|
+
def upload_chunk_intelligently(job, state, apikey, filepath, options, storage)
|
358
368
|
file = File.open(filepath)
|
359
|
-
file.seek(job[:
|
369
|
+
file.seek(job[:seek_point] + job[:offset])
|
370
|
+
|
360
371
|
chunk = file.read(state.offset)
|
361
372
|
md5 = Digest::MD5.new
|
362
373
|
md5 << chunk
|
@@ -368,17 +379,17 @@ module IntelligentUtils
|
|
368
379
|
uri: job[:uri],
|
369
380
|
region: job[:region],
|
370
381
|
upload_id: job[:upload_id],
|
371
|
-
|
382
|
+
store: { location: storage },
|
372
383
|
offset: job[:offset],
|
373
|
-
|
374
|
-
'multipart' => 'true'
|
384
|
+
fii: true
|
375
385
|
}
|
376
386
|
|
377
387
|
data = data.merge!(options) if options
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
388
|
+
|
389
|
+
fs_response = Typhoeus.post(FilestackConfig.multipart_upload_url(job[:location_url]),
|
390
|
+
body: data.to_json,
|
391
|
+
headers: FilestackConfig::HEADERS)
|
392
|
+
|
382
393
|
# POST to multipart/upload
|
383
394
|
begin
|
384
395
|
unless fs_response.code == 200
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filestack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Filestack
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -201,7 +201,7 @@ homepage: https://github.com/filestack/filestack-ruby
|
|
201
201
|
licenses:
|
202
202
|
- MIT
|
203
203
|
metadata: {}
|
204
|
-
post_install_message:
|
204
|
+
post_install_message:
|
205
205
|
rdoc_options: []
|
206
206
|
require_paths:
|
207
207
|
- lib
|
@@ -216,9 +216,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
216
|
- !ruby/object:Gem::Version
|
217
217
|
version: '0'
|
218
218
|
requirements: []
|
219
|
-
|
220
|
-
|
221
|
-
signing_key:
|
219
|
+
rubygems_version: 3.0.8
|
220
|
+
signing_key:
|
222
221
|
specification_version: 4
|
223
222
|
summary: Official Ruby SDK for the Filestack API
|
224
223
|
test_files: []
|