Method: Bcms::WebDAV::Resource#put

Defined in:
lib/bcms_webdav/resource.rb

#put(request, response) ⇒ Object

Handle uploading file.



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/bcms_webdav/resource.rb', line 136

def put(request, response)
  temp_file = extract_tempfile(request)
  section = find_section_for(path)

  file_block = Cms::FileBlock.new(:name=>path, :publish_on_save=>true)
  file_block.attachments.build(:data => temp_file, :attachment_name => 'file', :parent => section, :data_file_path => path)
  
  # Ensure the file pointer is at the beginning so Paperclip can copy after the block is saved.
  # Something in assigning the tempfile to the Block is not correctly rewinding the file.
  # Not doing this causes an empty file to be saved in uploads directory.
  temp_file.rewind
  
  unless file_block.save
    log "Couldn't save file."
    file_block.errors.each do |error|
      log error
    end
    work_around_dav4rack_bug
    return InternalServerError
  end
  Created
end