Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix filetype handling for url attachments

  • Loading branch information...
commit d57ed9f4fe6b9823ac6719d3b428a449a95220d4 1 parent ed2edeb
@nragaz authored
Showing with 9 additions and 7 deletions.
  1. +1 −1  lib/activerecord/base.rb
  2. +8 −6 lib/activeresource/base.rb
View
2  lib/activerecord/base.rb
@@ -16,7 +16,7 @@ def encode_attachment_in_xml(name, attachment_options={})
end
define_method "to_xml_with_encoded_#{name}" do |*args|
- # You can exclude file tags completely by using :include_files => false
+ # You can exclude file tags completely by using :include_attachments => false
# If :send_urls => true, force file encoding using :encode => true
options, block = args
View
14 lib/activeresource/base.rb
@@ -74,13 +74,15 @@ def has_encoded_attachment(name)
changed = (changed.nil? || changed) ? true : false
if file_url
url = URI.parse(file_url.to_s)
- send "#{name}_content_type=", MIME::Types.type_for(File.basename(url.path)).first.content_type
- send "#{name}=", StringIO.new(connection.get_attachment(url.path,
- 'Accept' => send("#{name}_content_type"))), changed
- send "#{name}_file_name=", File.basename(url.path)
- send "#{name}_content_type=", MIME::Types.type_for(File.basename(url.path)).first.content_type
+ content_type = MIME::Types.type_for(File.basename(url.path)).first.content_type
+
+ io = StringIO.new(connection.get_attachment(url.path, 'Accept' => content_type))
+ io.original_filename = File.basename(url.path)
+ io.content_type = content_type
+
+ send "#{name}=", io, changed
else
- send "#{name}=", nil, changed
+ send "#{name}=", nil, changed
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.