Reputation: 6244
I am utilizing the Cloudmailin service for users to upload profile pictures from mobile devices. Cloudmailin will forward an email in the form of an HTTP POST to our site. They have four methods to format the post. I am using the Multipart/form-data Hash Email Message Format because I thought it would be easier to pick up the attachment data. In my controller I have the following:
require 'mail'
skip_before_filter :verify_authenticity_token
def create
...
attachment = params[:attachments].first
file = StringIO.new(attachment.decoded)
...
end
Error Message:
NoMethodError (undefined method `decoded' for #<Array:0xb5060c24>)
I thought i might try using mms2r instead but in attempting to install the gem I got:
"Error installing mms2r: ERROR: Failed to build gem native extension."
Rather than solving the mms2r problem I'd rather make a go of it without it.
Thanks for your help.
Upvotes: 0
Views: 95
Reputation: 5211
The attachments passed are a hash starting with a key of 0. You need to iterate through each using something like
params[:attachments].each do |key,value|
# do something with value
logger.info value.inspect
end
This should give ou access to the tempfile. In the case of the multipart format there's no base64 encoding. The attachment is just sent as is and accessible via file as rack will extract the multipart file.
Upvotes: 1