Class: Account::AttachmentsController

Inherits:
BaseController show all
Includes:
Uploader::Authorization, Uploader::ChunkedUploads
Defined in:
app/controllers/account/attachments_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

caches_page_with_cache_marker, #raise_not_found!

Instance Method Details

#createObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/account/attachments_controller.rb', line 42

def create
  authorize!(:create, @asset)

  with_chunked_upload(asset_params[:data]) do |file|
    @asset.data = file
    @asset.fileupload_create(params, request)
  end

  @asset.errors.add(:data, :invalid) if @asset.remote_asset_id.blank?

  render_resourse @asset, 201
end

#destroyObject



31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/account/attachments_controller.rb', line 31

def destroy
  if @asset
    @asset.fileupload_destroy(params, request)
  else
    @remote_klass = @klass if defined?(@klass.destroy)
    @remote_klass ||= params[:klass].safe_constantize.try(:fileupload_klass, '')
    @asset = @remote_klass.destroy(destroy_params)
  end
  render json: @asset
end

#showObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/account/attachments_controller.rb', line 18

def show
  if data = TranslationCms::Utils::RemoteFile.new(@attachment['url']).fetch
    send_data(data.read,
              filename: @attachment['filename'],
              type: @attachment['content_type'],
              disposition: 'attachment',
              stream: true,
              buffer_size: 4096)
  else
    raise ActiveRecord::RecordNotFound, "Error download satellite file #{@attachment['id']}"
  end
end