Skip to content

Commit 5d92ae2

Browse files
committed
Add update with chunked media upload support
1 parent 1f8a494 commit 5d92ae2

7 files changed

+587
-2
lines changed

fixture/vcr_cassettes/update_destroy_status_with_chunked_media.json

+251
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
[
2+
{
3+
"request": {
4+
"body": "oauth_signature=<REMOVED>&oauth_consumer_key=<REMOVED>&oauth_nonce=<REMOVED>&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1567695912&oauth_version=1.0&oauth_token=<REMOVED>&command=INIT&total_bytes=257&media_type=image%2Fpng",
5+
"headers": [],
6+
"method": "post",
7+
"options": {
8+
"httpc_options": [],
9+
"http_options": {
10+
"autoredirect": "false"
11+
}
12+
},
13+
"request_body": "",
14+
"url": "https://upload.twitter.com/1.1/media/upload.json"
15+
},
16+
"response": {
17+
"body": "{\"media_id\":1169627541281394689,\"media_id_string\":\"1169627541281394689\",\"expires_after_secs\":86400}",
18+
"headers": {
19+
"cache-control": "no-cache, no-store, must-revalidate, pre-check=0, post-check=0",
20+
"date": "Thu, 05 Sep 2019 15:05:11 GMT",
21+
"pragma": "no-cache",
22+
"server": "tsa_b",
23+
"vary": "Origin",
24+
"content-length": "99",
25+
"content-type": "application/json;charset=utf-8",
26+
"expires": "Tue, 31 Mar 1981 05:00:00 GMT",
27+
"last-modified": "Thu, 05 Sep 2019 15:05:11 GMT",
28+
"content-disposition": "attachment; filename=json.json",
29+
"set-cookie": "personalization_id=\"v1_PUVgRa8/Hab1crgiyXIa/w==\"; Max-Age=63072000; Expires=Sat, 4 Sep 2021 15:05:11 GMT; Path=/; Domain=.twitter.com",
30+
"status": "202 Accepted",
31+
"strict-transport-security": "max-age=631138519",
32+
"x-access-level": "read-write",
33+
"x-connection-hash": "ab87b32a4c41fab2f541fd1ee828d3ae",
34+
"x-frame-options": "SAMEORIGIN",
35+
"x-mediaid": "1169627541281394689",
36+
"x-rate-limit-limit": "415",
37+
"x-rate-limit-remaining": "402",
38+
"x-rate-limit-reset": "1567697506",
39+
"x-response-time": "80",
40+
"x-transaction": "008a74ae006a08eb",
41+
"x-tsa-request-body-time": "1",
42+
"x-twitter-response-tags": "BouncerCompliant",
43+
"x-xss-protection": "1; mode=block"
44+
},
45+
"status_code": [
46+
"HTTP/1.1",
47+
202,
48+
"Accepted"
49+
],
50+
"type": "ok"
51+
}
52+
},
53+
{
54+
"request": {
55+
"body": "oauth_signature=<REMOVED>&oauth_consumer_key=<REMOVED>&oauth_nonce=<REMOVED>&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1567695912&oauth_version=1.0&oauth_token=<REMOVED>&command=APPEND&media_id=1169627541281394689&media_data=iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKAQMAAAC3%2FF3%2BAAAABGdBTUEAALGPC%2FxhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABlBMVEX%2F%2FwD%2F%2F%2F%2BLefOdAAAAAWJLR0QB%2FwIt3gAAAAtJREFUCNdjYMAHAAAeAAFuhUcyAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE1LTA4LTE1VDEzOjIzOjE3KzAyOjAw9TTaPgAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxNS0wOC0xNVQxMzoyMzoxNyswMjowMIRpYoIAAAAASUVORK5CYII%3D&segment_index=0",
56+
"headers": [],
57+
"method": "post",
58+
"options": {
59+
"httpc_options": [],
60+
"http_options": {
61+
"autoredirect": "false"
62+
}
63+
},
64+
"request_body": "",
65+
"url": "https://upload.twitter.com/1.1/media/upload.json"
66+
},
67+
"response": {
68+
"body": "",
69+
"headers": {
70+
"cache-control": "no-cache, no-store, must-revalidate, pre-check=0, post-check=0",
71+
"date": "Thu, 05 Sep 2019 15:05:11 GMT",
72+
"pragma": "no-cache",
73+
"server": "tsa_b",
74+
"vary": "Origin",
75+
"content-length": "0",
76+
"content-type": "text/html;charset=utf-8",
77+
"expires": "Tue, 31 Mar 1981 05:00:00 GMT",
78+
"last-modified": "Thu, 05 Sep 2019 15:05:11 GMT",
79+
"content-security-policy": "default-src 'self'; connect-src 'self'; font-src 'self' https://*.twimg.com https://twitter.com https://ton.twitter.com data:; frame-src 'self' https://*.twimg.com https://twitter.com https://ton.twitter.com; img-src 'self' https://*.twimg.com https://twitter.com https://ton.twitter.com data:; media-src 'self' https://*.twimg.com https://twitter.com https://ton.twitter.com; object-src 'none'; script-src 'self' https://*.twimg.com https://twitter.com https://ton.twitter.com; style-src 'self' https://*.twimg.com https://twitter.com https://ton.twitter.com; report-uri https://twitter.com/i/csp_report?a=OBZG6ZTJNRSWE2LSMQ%3D%3D%3D%3D%3D%3D&ro=false;",
80+
"set-cookie": "personalization_id=\"v1_YI4BQuU1yA21gfXvthq44w==\"; Max-Age=63072000; Expires=Sat, 4 Sep 2021 15:05:11 GMT; Path=/; Domain=.twitter.com",
81+
"status": "204 No Content",
82+
"strict-transport-security": "max-age=631138519",
83+
"x-access-level": "read-write",
84+
"x-connection-hash": "ab87b32a4c41fab2f541fd1ee828d3ae",
85+
"x-frame-options": "SAMEORIGIN",
86+
"x-mediaid": "1169627541281394689",
87+
"x-rate-limit-limit": "20000",
88+
"x-rate-limit-remaining": "19996",
89+
"x-rate-limit-reset": "1567698471",
90+
"x-response-time": "73",
91+
"x-segmentcount": "0",
92+
"x-totalbytes": "0",
93+
"x-transaction": "007801e60091414c",
94+
"x-tsa-request-body-time": "0",
95+
"x-twitter-response-tags": "BouncerCompliant",
96+
"x-xss-protection": "1; mode=block"
97+
},
98+
"status_code": [
99+
"HTTP/1.1",
100+
204,
101+
"No Content"
102+
],
103+
"type": "ok"
104+
}
105+
},
106+
{
107+
"request": {
108+
"body": "oauth_signature=<REMOVED>&oauth_consumer_key=<REMOVED>&oauth_nonce=<REMOVED>&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1567695912&oauth_version=1.0&oauth_token=<REMOVED>&command=FINALIZE&media_id=1169627541281394689",
109+
"headers": [],
110+
"method": "post",
111+
"options": {
112+
"httpc_options": [],
113+
"http_options": {
114+
"autoredirect": "false"
115+
}
116+
},
117+
"request_body": "",
118+
"url": "https://upload.twitter.com/1.1/media/upload.json"
119+
},
120+
"response": {
121+
"body": "{\"media_id\":1169627541281394689,\"media_id_string\":\"1169627541281394689\",\"size\":257,\"expires_after_secs\":86400,\"image\":{\"image_type\":\"image\\/png\",\"w\":10,\"h\":10}}",
122+
"headers": {
123+
"cache-control": "no-cache, no-store, must-revalidate, pre-check=0, post-check=0",
124+
"date": "Thu, 05 Sep 2019 15:05:11 GMT",
125+
"pragma": "no-cache",
126+
"server": "tsa_b",
127+
"vary": "Origin",
128+
"content-length": "160",
129+
"content-type": "application/json;charset=utf-8",
130+
"expires": "Tue, 31 Mar 1981 05:00:00 GMT",
131+
"last-modified": "Thu, 05 Sep 2019 15:05:11 GMT",
132+
"content-disposition": "attachment; filename=json.json",
133+
"set-cookie": "personalization_id=\"v1_0CvpJQnbDFYICnq7R3kWwA==\"; Max-Age=63072000; Expires=Sat, 4 Sep 2021 15:05:11 GMT; Path=/; Domain=.twitter.com",
134+
"status": "201 Created",
135+
"strict-transport-security": "max-age=631138519",
136+
"x-access-level": "read-write",
137+
"x-connection-hash": "ab87b32a4c41fab2f541fd1ee828d3ae",
138+
"x-frame-options": "SAMEORIGIN",
139+
"x-mediaid": "1169627541281394689",
140+
"x-rate-limit-limit": "615",
141+
"x-rate-limit-remaining": "611",
142+
"x-rate-limit-reset": "1567698471",
143+
"x-response-time": "219",
144+
"x-transaction": "0094704100bd4e28",
145+
"x-tsa-request-body-time": "1",
146+
"x-twitter-response-tags": "BouncerCompliant",
147+
"x-xss-protection": "1; mode=block"
148+
},
149+
"status_code": [
150+
"HTTP/1.1",
151+
201,
152+
"Created"
153+
],
154+
"type": "ok"
155+
}
156+
},
157+
{
158+
"request": {
159+
"body": "oauth_signature=<REMOVED>&oauth_consumer_key=<REMOVED>&oauth_nonce=<REMOVED>&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1567695912&oauth_version=1.0&oauth_token=<REMOVED>&status=update+sample+with+chunked+media&media_ids=1169627541281394689&trim_user=true&chunked_size=131072",
160+
"headers": [],
161+
"method": "post",
162+
"options": {
163+
"httpc_options": [],
164+
"http_options": {
165+
"autoredirect": "false"
166+
}
167+
},
168+
"request_body": "",
169+
"url": "https://api.twitter.com/1.1/statuses/update.json"
170+
},
171+
"response": {
172+
"body": "{\"created_at\":\"Thu Sep 05 15:05:11 +0000 2019\",\"id\":1169627544305524736,\"id_str\":\"1169627544305524736\",\"text\":\"update sample with chunked media https:\\/\\/t.co\\/UK7h1571oi\",\"truncated\":false,\"entities\":{\"hashtags\":[],\"symbols\":[],\"user_mentions\":[],\"urls\":[],\"media\":[{\"id\":1169627541281394689,\"id_str\":\"1169627541281394689\",\"indices\":[33,56],\"media_url\":\"http:\\/\\/pbs.twimg.com\\/media\\/EDtaDUWXUAEaZJf.png\",\"media_url_https\":\"https:\\/\\/pbs.twimg.com\\/media\\/EDtaDUWXUAEaZJf.png\",\"url\":\"https:\\/\\/t.co\\/UK7h1571oi\",\"display_url\":\"pic.twitter.com\\/UK7h1571oi\",\"expanded_url\":\"https:\\/\\/twitter.com\\/testtest\\/status\\/1169627544305524736\\/photo\\/1\",\"type\":\"photo\",\"sizes\":{\"thumb\":{\"w\":10,\"h\":10,\"resize\":\"crop\"},\"small\":{\"w\":10,\"h\":10,\"resize\":\"fit\"},\"medium\":{\"w\":10,\"h\":10,\"resize\":\"fit\"},\"large\":{\"w\":10,\"h\":10,\"resize\":\"fit\"}}}]},\"extended_entities\":{\"media\":[{\"id\":1169627541281394689,\"id_str\":\"1169627541281394689\",\"indices\":[33,56],\"media_url\":\"http:\\/\\/pbs.twimg.com\\/media\\/EDtaDUWXUAEaZJf.png\",\"media_url_https\":\"https:\\/\\/pbs.twimg.com\\/media\\/EDtaDUWXUAEaZJf.png\",\"url\":\"https:\\/\\/t.co\\/UK7h1571oi\",\"display_url\":\"pic.twitter.com\\/UK7h1571oi\",\"expanded_url\":\"https:\\/\\/twitter.com\\/testtest\\/status\\/1169627544305524736\\/photo\\/1\",\"type\":\"photo\",\"sizes\":{\"thumb\":{\"w\":10,\"h\":10,\"resize\":\"crop\"},\"small\":{\"w\":10,\"h\":10,\"resize\":\"fit\"},\"medium\":{\"w\":10,\"h\":10,\"resize\":\"fit\"},\"large\":{\"w\":10,\"h\":10,\"resize\":\"fit\"}}}]},\"source\":\"\\u003ca href=\\\"http:\\/\\/example.com\\\" rel=\\\"nofollow\\\"\\u003eExample\\u003c\\/a\\u003e\",\"in_reply_to_status_id\":null,\"in_reply_to_status_id_str\":null,\"in_reply_to_user_id\":null,\"in_reply_to_user_id_str\":null,\"in_reply_to_screen_name\":null,\"user\":{\"id\":4860209540,\"id_str\":\"4860209540\"},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"is_quote_status\":false,\"retweet_count\":0,\"favorite_count\":0,\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false,\"lang\":\"en\"}",
173+
"headers": {
174+
"cache-control": "no-cache, no-store, must-revalidate, pre-check=0, post-check=0",
175+
"date": "Thu, 05 Sep 2019 15:05:11 GMT",
176+
"pragma": "no-cache",
177+
"server": "tsa_b",
178+
"content-length": "1936",
179+
"content-type": "application/json;charset=utf-8",
180+
"expires": "Tue, 31 Mar 1981 05:00:00 GMT",
181+
"last-modified": "Thu, 05 Sep 2019 15:05:11 GMT",
182+
"content-disposition": "attachment; filename=json.json",
183+
"set-cookie": "personalization_id=\"v1_AMljjZKee1EkpXCxPlOmAw==\"; Max-Age=63072000; Expires=Sat, 4 Sep 2021 15:05:11 GMT; Path=/; Domain=.twitter.com",
184+
"status": "200 OK",
185+
"strict-transport-security": "max-age=631138519",
186+
"x-access-level": "read-write",
187+
"x-connection-hash": "ac284322951ab9bb781021faab0b804e",
188+
"x-content-type-options": "nosniff",
189+
"x-frame-options": "SAMEORIGIN",
190+
"x-response-time": "158",
191+
"x-transaction": "006242d200e18762",
192+
"x-tsa-request-body-time": "0",
193+
"x-twitter-response-tags": "BouncerCompliant",
194+
"x-xss-protection": "0"
195+
},
196+
"status_code": [
197+
"HTTP/1.1",
198+
200,
199+
"OK"
200+
],
201+
"type": "ok"
202+
}
203+
},
204+
{
205+
"request": {
206+
"body": "oauth_signature=<REMOVED>&oauth_consumer_key=<REMOVED>&oauth_nonce=<REMOVED>&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1567695912&oauth_version=1.0&oauth_token=<REMOVED>",
207+
"headers": [],
208+
"method": "post",
209+
"options": {
210+
"httpc_options": [],
211+
"http_options": {
212+
"autoredirect": "false"
213+
}
214+
},
215+
"request_body": "",
216+
"url": "https://api.twitter.com/1.1/statuses/destroy/1169627544305524736.json"
217+
},
218+
"response": {
219+
"body": "{\"created_at\":\"Thu Sep 05 15:05:11 +0000 2019\",\"id\":1169627544305524736,\"id_str\":\"1169627544305524736\",\"text\":\"update sample with chunked media https:\\/\\/t.co\\/UK7h1571oi\",\"truncated\":false,\"entities\":{\"hashtags\":[],\"symbols\":[],\"user_mentions\":[],\"urls\":[],\"media\":[{\"id\":1169627541281394689,\"id_str\":\"1169627541281394689\",\"indices\":[33,56],\"media_url\":\"http:\\/\\/pbs.twimg.com\\/media\\/EDtaDUWXUAEaZJf.png\",\"media_url_https\":\"https:\\/\\/pbs.twimg.com\\/media\\/EDtaDUWXUAEaZJf.png\",\"url\":\"https:\\/\\/t.co\\/UK7h1571oi\",\"display_url\":\"pic.twitter.com\\/UK7h1571oi\",\"expanded_url\":\"https:\\/\\/twitter.com\\/testtest\\/status\\/1169627544305524736\\/photo\\/1\",\"type\":\"photo\",\"sizes\":{\"thumb\":{\"w\":10,\"h\":10,\"resize\":\"crop\"},\"small\":{\"w\":10,\"h\":10,\"resize\":\"fit\"},\"large\":{\"w\":10,\"h\":10,\"resize\":\"fit\"},\"medium\":{\"w\":10,\"h\":10,\"resize\":\"fit\"}}}]},\"extended_entities\":{\"media\":[{\"id\":1169627541281394689,\"id_str\":\"1169627541281394689\",\"indices\":[33,56],\"media_url\":\"http:\\/\\/pbs.twimg.com\\/media\\/EDtaDUWXUAEaZJf.png\",\"media_url_https\":\"https:\\/\\/pbs.twimg.com\\/media\\/EDtaDUWXUAEaZJf.png\",\"url\":\"https:\\/\\/t.co\\/UK7h1571oi\",\"display_url\":\"pic.twitter.com\\/UK7h1571oi\",\"expanded_url\":\"https:\\/\\/twitter.com\\/testtest\\/status\\/1169627544305524736\\/photo\\/1\",\"type\":\"photo\",\"sizes\":{\"thumb\":{\"w\":10,\"h\":10,\"resize\":\"crop\"},\"small\":{\"w\":10,\"h\":10,\"resize\":\"fit\"},\"large\":{\"w\":10,\"h\":10,\"resize\":\"fit\"},\"medium\":{\"w\":10,\"h\":10,\"resize\":\"fit\"}}}]},\"source\":\"\\u003ca href=\\\"http:\\/\\/example.com\\\" rel=\\\"nofollow\\\"\\u003eExample\\u003c\\/a\\u003e\",\"in_reply_to_status_id\":null,\"in_reply_to_status_id_str\":null,\"in_reply_to_user_id\":null,\"in_reply_to_user_id_str\":null,\"in_reply_to_screen_name\":null,\"user\":{\"id\":4860209540,\"id_str\":\"4860209540\",\"name\":\"Test Test\",\"screen_name\":\"testtest\",\"location\":\"\",\"description\":\"\",\"url\":null,\"entities\":{\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":1,\"friends_count\":0,\"listed_count\":0,\"created_at\":\"Thu Feb 04 18:53:22 +0000 2016\",\"favourites_count\":5,\"utc_offset\":null,\"time_zone\":null,\"geo_enabled\":false,\"verified\":false,\"statuses_count\":27409,\"lang\":null,\"contributors_enabled\":false,\"is_translator\":false,\"is_translation_enabled\":false,\"profile_background_color\":\"F5F8FA\",\"profile_background_image_url\":null,\"profile_background_image_url_https\":null,\"profile_background_tile\":false,\"profile_image_url\":\"http:\\/\\/abs.twimg.com\\/sticky\\/default_profile_images\\/default_profile_normal.png\",\"profile_image_url_https\":\"https:\\/\\/abs.twimg.com\\/sticky\\/default_profile_images\\/default_profile_normal.png\",\"profile_link_color\":\"1DA1F2\",\"profile_sidebar_border_color\":\"C0DEED\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"has_extended_profile\":false,\"default_profile\":true,\"default_profile_image\":true,\"following\":false,\"follow_request_sent\":false,\"notifications\":false,\"translator_type\":\"none\"},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"is_quote_status\":false,\"retweet_count\":0,\"favorite_count\":0,\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false,\"lang\":\"en\"}",
220+
"headers": {
221+
"cache-control": "no-cache, no-store, must-revalidate, pre-check=0, post-check=0",
222+
"date": "Thu, 05 Sep 2019 15:05:12 GMT",
223+
"pragma": "no-cache",
224+
"server": "tsa_b",
225+
"content-length": "3106",
226+
"content-type": "application/json;charset=utf-8",
227+
"expires": "Tue, 31 Mar 1981 05:00:00 GMT",
228+
"last-modified": "Thu, 05 Sep 2019 15:05:12 GMT",
229+
"content-disposition": "attachment; filename=json.json",
230+
"set-cookie": "personalization_id=\"v1_SY8hX8qNItpP6nnkEyJb+A==\"; Max-Age=63072000; Expires=Sat, 4 Sep 2021 15:05:12 GMT; Path=/; Domain=.twitter.com",
231+
"status": "200 OK",
232+
"strict-transport-security": "max-age=631138519",
233+
"x-access-level": "read-write",
234+
"x-connection-hash": "ac284322951ab9bb781021faab0b804e",
235+
"x-content-type-options": "nosniff",
236+
"x-frame-options": "SAMEORIGIN",
237+
"x-response-time": "34",
238+
"x-transaction": "00b0fda200c95251",
239+
"x-tsa-request-body-time": "0",
240+
"x-twitter-response-tags": "BouncerCompliant",
241+
"x-xss-protection": "0"
242+
},
243+
"status_code": [
244+
"HTTP/1.1",
245+
200,
246+
"OK"
247+
],
248+
"type": "ok"
249+
}
250+
}
251+
]

lib/extwitter.ex

+38
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,44 @@ defmodule ExTwitter do
387387
@impl Behaviour
388388
defdelegate update_with_media(status, media_content, options), to: ExTwitter.API.Tweets
389389

390+
@doc """
391+
POST upload.twitter.com/1.1/media/upload (INIT/APPEND/FINALIZE)
392+
POST statuses/update
393+
394+
The default chunk size is 64kb (65,536 bytes). This can be adjusted via `update_with_chunked_media/4`.
395+
396+
## Examples
397+
398+
ExTwitter.update_with_chunked_media("tweet with chunked media", "/path/to/file.mp4", "video/mp4")
399+
400+
## Reference
401+
https://developer.twitter.com/en/docs/media/upload-media/overview
402+
403+
## Note
404+
Unlike `update_with_media/3`, this supports the uploading of all Twitter-supported media types such as video files.
405+
"""
406+
@impl Behaviour
407+
defdelegate update_with_chunked_media(status, path, content_type), to: ExTwitter.API.Tweets
408+
409+
@doc """
410+
POST upload.twitter.com/1.1/media/upload (INIT/APPEND/FINALIZE)
411+
POST statuses/update
412+
413+
Chunk size (in bytes) can be configured via the `:chunk_size` option. The default is 64kb (65,536 bytes).
414+
415+
## Examples
416+
417+
ExTwitter.update_with_chunked_media("tweet with chunked media", "/path/to/file.mp4", "video/mp4", trim_user: true, chunk_size: 131_072)
418+
419+
## Reference
420+
https://developer.twitter.com/en/docs/media/upload-media/overview
421+
422+
## Note
423+
Unlike `update_with_media/3`, this supports the uploading of all Twitter-supported media types such as video files.
424+
"""
425+
@impl Behaviour
426+
defdelegate update_with_chunked_media(status, path, content_type, options), to: ExTwitter.API.Tweets
427+
390428
@doc """
391429
Chunk upload media and return media_id.
392430
POST media/upload (INIT)

lib/extwitter/api/base.ex

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ defmodule ExTwitter.API.Base do
55

66
# https://dev.twitter.com/overview/api/response-codes
77
@error_code_rate_limit_exceeded 88
8+
@default_chunk_size 65536 # 64kb
89

910
@doc """
1011
Send request to the api.twitter.com server.
@@ -13,10 +14,14 @@ defmodule ExTwitter.API.Base do
1314
do_request(method, request_url(path), params)
1415
end
1516

17+
def default_chunk_size do
18+
@default_chunk_size
19+
end
20+
1621
@doc """
1722
Upload media in chunks
1823
"""
19-
def upload_media(path, content_type, chunk_size \\ 65536) do
24+
def upload_media(path, content_type, chunk_size \\ @default_chunk_size) do
2025
media_id = init_media_upload(path, content_type)
2126
upload_file_chunks(path, media_id, chunk_size)
2227
finalize_upload(media_id)
@@ -35,7 +40,9 @@ defmodule ExTwitter.API.Base do
3540
initial_segment_index = 0
3641
Enum.reduce(stream, initial_segment_index, fn(chunk, seg_index) ->
3742
request_params = [command: "APPEND", media_id: media_id, media_data: Base.encode64(chunk), segment_index: seg_index]
38-
{:ok, {{_proto, 204, _status_description}, _headers, _body}} = do_request(:post, media_upload_url(), request_params, parse_result: false)
43+
case do_request(:post, media_upload_url(), request_params, parse_result: false) do
44+
{:ok, {{_proto, status_code, _status_description}, _headers, _body}} when status_code in 200..299 -> :ok
45+
end
3946
seg_index + 1
4047
end)
4148
end

0 commit comments

Comments
 (0)