lib/locomotive/coal/upload_io.rb in locomotivecms_coal-1.5.0 vs lib/locomotive/coal/upload_io.rb in locomotivecms_coal-1.5.1
- old
+ new
@@ -1,10 +1,18 @@
module Locomotive::Coal
class UploadIO < ::Faraday::UploadIO
def initialize(filename_or_io, content_type = nil, filename = nil)
- super(filename_or_io, content_type || 'application/octet-stream', filename)
+ if filename.blank? && filename_or_io.is_a?(String)
+ filename = File.basename(filename_or_io)
+ end
+
+ super(
+ filename_or_io,
+ content_type || MIME::Types.type_for(filename).first || 'application/octet-stream',
+ filename
+ )
end
end
end