Class: TpCommon::FileStorage::Uploaders::Private

Inherits:
Base
  • Object
show all
Defined in:
lib/tp_common/file_storage/uploaders/private.rb

Overview

Upload a content to file storage used for private purpose like user import. export files Use in case content to upload is inside of system/server

Constant Summary

Constants inherited from Base

Base::MAX_RETRIES

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from TpCommon::FileStorage::Base

Instance Method Details

#upload(file_key, content, content_type) ⇒ Object

Upload content to file_key


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tp_common/file_storage/uploaders/private.rb', line 10

def upload(file_key, content, content_type)
  retry_count = 0

  begin
    directory.files.create(
      'key' => mask_key(file_key),
      "body" =>  content,
      'public' =>  false,
      'Content-Type' => content_type,
      "Content-Disposition" => "attachment;filename=\"#{mask_key(file_key)}\""
    )
  rescue StandardError => e
    retry_count += 1
    retry if retry_count < MAX_RETRIES
    raise e
  end

  mask_key(file_key)
end

#url(file_key, link_ttl = 1.week.from_now) ⇒ Object

Get url from key of file #upload above to provide to outside.

To get file content to use inside system, please use Downloaders::Private instead

As private file, link has a ttl, default 1 week.


33
34
35
# File 'lib/tp_common/file_storage/uploaders/private.rb', line 33

def url(file_key, link_ttl = 1.week.from_now)
  directory.files.get_https_url(mask_key(file_key), link_ttl)
end