Class: Vapi::FileUtilities

Inherits:
Object
  • Object
show all
Defined in:
lib/core/file_utilities.rb

Overview

Utility class for managing files.

Class Method Summary collapse

Class Method Details

.as_faraday_multipart(file_like:) ⇒ Faraday::Multipart::FilePart

Parameters:

  • file_like (String, IO)

    The file to be uploaded, or a string path to the file.

Returns:

  • (Faraday::Multipart::FilePart)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/core/file_utilities.rb', line 11

def self.as_faraday_multipart(file_like:)
  path = if file_like.is_a?(String)
           file_like
         else
           file_like.path
         end
  mime_type = MiniMime.lookup_by_filename(path)
  mime_type = if mime_type.nil?
                "application/octet-stream"
              else
                mime_type.content_type
              end
  Faraday::Multipart::FilePart.new(file_like, mime_type)
end