Class: Vellum::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)


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

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