make attachment upload WORK

lets see if we can make it GOOD, I think it already is FAST ^^
pull/3032/head
Jan Sandbrink 10 years ago
parent 4964255323
commit db3b9da3a8
  1. 25
      lib/api/v3/attachments/attachments_by_work_package_api.rb

@ -40,6 +40,31 @@ module API
attachments.count,
self_path)
end
post do
authorize(:edit_work_packages, context: @work_package.project)
metadata = params[:metadata]
file = params[:file]
# TODO: verify input (valid JSON + file given)
# FIXME: we should be using the representer to parse the metadata
parsed_metadata = JSON.parse(metadata)
uploaded_file = Rack::Multipart::UploadedFile.new file[:tempfile].path,
file[:type],
true
# I wish I could set the file name in a better way *sigh*
uploaded_file.instance_variable_set(:@original_filename, parsed_metadata['fileName'])
attachment = Attachment.new(file: uploaded_file,
container: @work_package,
description: parsed_metadata['description']['raw'],
author: current_user)
attachment.save!
::API::V3::Attachments::AttachmentRepresenter.new(attachment)
end
end
end
end

Loading…
Cancel
Save