Sha256: 9a64ee9f816a84c08048a54c3c6134f106e72c9df67f0565af775b61a9cc5818

Contents?: true

Size: 809 Bytes

Versions: 12

Compression:

Stored size: 809 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  # A concern to help when the file needs to be available locally.
  # For example, we need to download file first if it's in AWS S3 bucket
  # or somewhere else than locally in the server.
  module ProcessesFileLocally
    extend ActiveSupport::Concern

    private

    def process_file_locally(blob)
      if ActiveStorage::Blob.service.respond_to? :path_for
        yield ActiveStorage::Blob.service.path_for(blob.key)
      else
        begin
          tempfile = Tempfile.new
          tempfile.binmode
          blob.download { |chunk| tempfile.write(chunk) }
          tempfile.flush
          tempfile.rewind
          yield tempfile.path
        ensure
          tempfile.close!
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-core-0.27.9 lib/decidim/processes_file_locally.rb
decidim-core-0.27.8 lib/decidim/processes_file_locally.rb
decidim-core-0.27.7 lib/decidim/processes_file_locally.rb
decidim-core-0.27.6 lib/decidim/processes_file_locally.rb
decidim-core-0.27.5 lib/decidim/processes_file_locally.rb
decidim-core-0.27.4 lib/decidim/processes_file_locally.rb
decidim-core-0.27.3 lib/decidim/processes_file_locally.rb
decidim-core-0.27.2 lib/decidim/processes_file_locally.rb
decidim-core-0.27.1 lib/decidim/processes_file_locally.rb
decidim-core-0.27.0 lib/decidim/processes_file_locally.rb
decidim-core-0.27.0.rc2 lib/decidim/processes_file_locally.rb
decidim-core-0.27.0.rc1 lib/decidim/processes_file_locally.rb