Class: TpCommon::FileStorage::Uploaders::Public
- Defined in:
- lib/tp_common/file_storage/uploaders/public.rb
Overview
Upload a content to file storage used to public like avatar, logo Use in case content to upload is inside of system/server
Constant Summary
Constants inherited from Base
Instance Method Summary collapse
- #exists?(file_key) ⇒ Boolean
-
#upload(file_key, content, _content_type = nil) ⇒ Object
Upload content to file_key Currently, _content_type is ignore but kept for compatible.
-
#url(file_key) ⇒ Object
Get public url from key of file #upload above.
Methods inherited from Base
Constructor Details
This class inherits a constructor from TpCommon::FileStorage::Base
Instance Method Details
#exists?(file_key) ⇒ Boolean
35 36 37 |
# File 'lib/tp_common/file_storage/uploaders/public.rb', line 35 def exists?(file_key) !!directory.files.head(mask_key(file_key)) end |
#upload(file_key, content, _content_type = nil) ⇒ Object
Upload content to file_key Currently, _content_type is ignore but kept for compatible. Will be removed in next release
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tp_common/file_storage/uploaders/public.rb', line 11 def upload(file_key, content, _content_type = nil) retry_count = 0 begin directory.files.create( key: mask_key(file_key), body: content, public: true) rescue StandardError => e retry_count += 1 retry if retry_count < MAX_RETRIES raise e end mask_key(file_key) end |
#url(file_key) ⇒ Object
Get public url from key of file #upload above
30 31 32 |
# File 'lib/tp_common/file_storage/uploaders/public.rb', line 30 def url(file_key) directory.files.get(mask_key(file_key))&.public_url end |