Module: PresignedUpload::Uploadable::Model

Extended by:
ActiveSupport::Concern
Includes:
PresignedUpload::Uploadable
Defined in:
lib/presigned_upload/uploadable.rb

Overview

The ‘Model` submodule extends ActiveSupport::Concern to provide upload-related functionality to ActiveRecord models.

Instance Method Summary collapse

Methods included from Storage

#delete_file, #presigned_url

Instance Method Details

#delete_stored_fileObject

Deletes the stored file associated with the model.



68
69
70
# File 'lib/presigned_upload/uploadable.rb', line 68

def delete_stored_file
  delete_file(store_path)
end

#store_pathString

Returns the file store path.

The store path is constructed by combining the storage directory

with the `original_name` of the file. If `store_dir` is present, it is
included in the path. If `store_dir` is not present, then the file
will be saved in the root directory.

Returns:

  • (String)

    the storage path for the uploaded file.



80
81
82
# File 'lib/presigned_upload/uploadable.rb', line 80

def store_path
  "#{store_dir.present? ? "#{store_dir}/" : ""}#{original_name}"
end

#upload_urlString?

Returns a presigned URL for uploading the file. Returns ‘nil` if the upload status is ’completed’.

Returns:

  • (String, nil)

    The presigned URL for uploading the file or ‘nil` if the upload status is already marked as completed.



60
61
62
63
64
# File 'lib/presigned_upload/uploadable.rb', line 60

def upload_url
  return if completed?

  presigned_url(store_path, :put)
end

#urlString?

Returns a presigned URL for accessing the stored file. Returns ‘nil` if the upload status is not ’completed’.

Returns:

  • (String, nil)

    The presigned URL for accessing the stored file or ‘nil` if the upload status is not completed.



49
50
51
52
53
# File 'lib/presigned_upload/uploadable.rb', line 49

def url
  return unless completed?

  presigned_url(store_path, :get)
end