在看
gem documentation
,看起来你不需要使用
write
方法,但使用
to_s
方法,该方法应创建xml字符串,然后您可以使用Tempfile将其与活动存储一起上载:
这是你的答案
到\u s
方法
def to_s(update_time = true)
@time = Time.now if @time.nil? || update_time
doc = generate_xml_doc
doc.to_xml
end
#so assuming you have something like this:
bounds = GPX::Bounds.new(params)
file = Tempfile.new('foo')
file.path # => A unique filename in the OS's temp directory,
# e.g.: "/tmp/foo.24722.0"
# This filename contains 'foo' in its basename.
file.write bounds.to_s
file.rewind
@message.image.attach(io: file.read, filename: 'some_s3_file_name.xml')
file.close
file.unlink # deletes the temp file
bounds = GPX::Bounds.new(params)
@message.image.attach(io: StringIO.new(bounds.to_s), name: 'some_s3_file_name.xml')