Class: TentD::API::Posts::CreateAttachments

Inherits:
Middleware
  • Object
show all
Defined in:
lib/tentd/api/posts.rb

Instance Method Summary collapse

Methods inherited from Middleware

#call, #initialize

Methods included from Authorizable

#authorize_env!, #authorize_env?

Constructor Details

This class inherits a constructor from TentD::API::Middleware

Instance Method Details

#action(env) ⇒ Object



243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/tentd/api/posts.rb', line 243

def action(env)
  return env unless env.params.attachments.kind_of?(Array) && env.response
  post = env.response
  version = post.latest_version(:fields => [:id])
  env.params.attachments.each do |attachment|
    Model::PostAttachment.create(:post => post,
                                 :post_version => version,
                                 :type => attachment.type,
                                 :category => attachment.name, :name => attachment.filename,
                                 :data => Base64.encode64(attachment.tempfile.read), :size => attachment.tempfile.size)
  end
  env.response.reload
  env
end