Class: NeetoCommonsBackend::Api::DirectUploadsController

Inherits:
ActiveStorage::DirectUploadsController
  • Object
show all
Defined in:
app/controllers/neeto_commons_backend/api/direct_uploads_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



9
10
11
12
13
# File 'app/controllers/neeto_commons_backend/api/direct_uploads_controller.rb', line 9

def create
  @blob = ActiveStorage::Blob.create_before_direct_upload!(**blob_args)
  blob_url = url_for(@blob)
  render json: direct_upload_json(@blob).merge(blob_url:)
end

#destroyObject



20
21
22
23
24
25
26
27
# File 'app/controllers/neeto_commons_backend/api/direct_uploads_controller.rb', line 20

def destroy
  @blob.attachments.each do |attachment|
    attachment.record&.touch
    attachment.purge
  end
  @blob&.purge
  render status: :ok, json: { notice: "Attachment has been successfully deleted." }
end

#updateObject



15
16
17
18
# File 'app/controllers/neeto_commons_backend/api/direct_uploads_controller.rb', line 15

def update
  @blob.update! blob_params
  render status: :ok, json: { notice: "Attachment has been successfully updated.", blob: @blob }
end