Skip to content

Commit

Permalink
add mov chunk_uplaod
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohta Kimura committed Jun 20, 2023
1 parent 5fc9b15 commit a57a597
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/twitter/rest/upload_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ module UploadUtils
#
# @see https://developer.twitter.com/en/docs/media/upload-media/uploading-media/media-best-practices
def upload(media, media_category_prefix: "tweet")
return chunk_upload(media, "video/mp4", "#{media_category_prefix}_video") if File.extname(media) == ".mp4"
return chunk_upload(media, "image/gif", "#{media_category_prefix}_gif") if File.extname(media) == ".gif" && File.size(media) > 5_000_000
ext = File.extname(media)
return chunk_upload(media, "video/mp4", "#{media_category_prefix}_video") if ext == ".mp4"
return chunk_upload(media, "video/quicktime", "#{media_category_prefix}_video") if ext == ".mov"
return chunk_upload(media, "image/gif", "#{media_category_prefix}_gif") if ext == ".gif" && File.size(media) > 5_000_000

Twitter::REST::Request.new(self, :multipart_post, "https://upload.twitter.com/1.1/media/upload.json", key: :media, file: media).perform
end
Expand Down

0 comments on commit a57a597

Please sign in to comment.