class RemoveBg::Upload

Constants

FARADAY_FILE

UploadIO for Faraday < 0.16.0

Public Class Methods

for_file(file_path) click to toggle source
# File lib/remove_bg/upload.rb, line 6
def self.for_file(file_path)
  if !File.exist?(file_path)
    raise RemoveBg::FileMissingError.new(file_path)
  end

  content_type = determine_content_type(file_path)
  FARADAY_FILE.new(file_path, content_type)
end

Private Class Methods

determine_content_type(file_path) click to toggle source
# File lib/remove_bg/upload.rb, line 15
def self.determine_content_type(file_path)
  case File.extname(file_path).downcase
  when ".jpg", ".jpeg" then "image/jpeg"
  when ".png" then "image/png"
  else
    raise RemoveBg::Error, "Unsupported file type (#{file_path})"
  end
end