Class: Workarea::Admin::DirectUploadsController
- Inherits:
-
ApplicationController
- Object
- Workarea::ApplicationController
- ApplicationController
- Workarea::Admin::DirectUploadsController
- Defined in:
- app/controllers/workarea/admin/direct_uploads_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #new ⇒ Object
- #product_images ⇒ Object
-
#upload ⇒ Object
This is only used when no S3 config present (like local development).
Methods inherited from ApplicationController
#current_user, #find_sort, #wrap_in_view_model, wrap_in_view_model
Methods included from Publishing
#allow_publishing!, #allow_publishing?, #set_publishing_options
Methods included from Visiting
Instance Method Details
#create ⇒ Object
19 20 21 22 |
# File 'app/controllers/workarea/admin/direct_uploads_controller.rb', line 19 def create ProcessDirectUpload.perform_async(params[:type], params[:filename]) request.xhr? ? head(:ok) : redirect_back(fallback_location: root_path) end |
#new ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'app/controllers/workarea/admin/direct_uploads_controller.rb', line 8 def new direct_upload = DirectUpload.new(params[:type], params[:filename]) if direct_upload.valid? render json: { upload_url: direct_upload.upload_url }, status: :ok else errors = direct_upload.errors..to_sentence render json: { error: errors }, status: :unprocessable_entity end end |
#product_images ⇒ Object
4 5 6 |
# File 'app/controllers/workarea/admin/direct_uploads_controller.rb', line 4 def product_images DirectUpload.ensure_cors!(request.url) if Configuration::S3.configured? end |
#upload ⇒ Object
This is only used when no S3 config present (like local development)
When this is used, Fog will be in mock mode (Fog.mock!) so it simulates the use of a direct-to-S3 upload.
28 29 30 31 32 33 |
# File 'app/controllers/workarea/admin/direct_uploads_controller.rb', line 28 def upload upload = DirectUpload.new(params[:type], "#{params[:filename]}.#{params[:format]}") Workarea.s3.put_bucket(Configuration::S3.bucket) rescue nil Workarea.s3.put_object(Configuration::S3.bucket, upload.key, request.body) end |