summaryrefslogtreecommitdiff
path: root/app/controllers/concerns/uploads_actions.rb
diff options
context:
space:
mode:
authorJarka Kadlecova <jarka@gitlab.com>2017-05-01 15:14:35 +0200
committerJarka Kadlecova <jarka@gitlab.com>2017-05-02 15:22:24 +0200
commit43ff7386411af0f538710f3627622f71e5e34472 (patch)
tree3bb4d32c1389504d70395f36e8e223899fcbccd5 /app/controllers/concerns/uploads_actions.rb
parent6277bda61c511696f9d12fae4238b5214a722571 (diff)
downloadgitlab-ce-43ff7386411af0f538710f3627622f71e5e34472.tar.gz
Support uploaders for personal snippets comments12910-uploader-pers-snippet
Diffstat (limited to 'app/controllers/concerns/uploads_actions.rb')
-rw-r--r--app/controllers/concerns/uploads_actions.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/app/controllers/concerns/uploads_actions.rb b/app/controllers/concerns/uploads_actions.rb
new file mode 100644
index 00000000000..dec2e27335a
--- /dev/null
+++ b/app/controllers/concerns/uploads_actions.rb
@@ -0,0 +1,27 @@
+module UploadsActions
+ def create
+ link_to_file = UploadService.new(model, params[:file], uploader_class).execute
+
+ respond_to do |format|
+ if link_to_file
+ format.json do
+ render json: { link: link_to_file }
+ end
+ else
+ format.json do
+ render json: 'Invalid file.', status: :unprocessable_entity
+ end
+ end
+ end
+ end
+
+ def show
+ return render_404 unless uploader.exists?
+
+ disposition = uploader.image_or_video? ? 'inline' : 'attachment'
+
+ expires_in 0.seconds, must_revalidate: true, private: true
+
+ send_file uploader.file.path, disposition: disposition
+ end
+end