Sha256: 21d41829cb72f8d1f976e7506c7bef7534a034a3f6e70daf846568e2c91ca55a

Contents?: true

Size: 870 Bytes

Versions: 3

Compression:

Stored size: 870 Bytes

Contents

require 'fiona7/builder/indirect_blob_builder'
require 'fiona7/upload_path_selector'
require 'fiona7/blob_id_generator'

module Fiona7
  # This class uploads a file into a temporary location to be reused later.
  # It returns the blob id of the uploaded file.
  class TemporaryUploader
    def initialize(file, filename, obj_id=nil)
      @file     = file
      @filename = filename
      @obj_id   = obj_id
    end

    def call
      obj = Builder::IndirectBlobBuilder.new(upload_path, @filename, @file).call
      BlobIdGenerator.new(obj.obj_id, obj.last_changed).call
    end

    private
    def upload_path
      if Fiona7.mode == :standalone
        dest_obj = Fiona7::WriteObj.find(@obj_id) rescue nil
        if dest_obj
          return UploadPathSelector.new(dest_obj).call
        end
      end

      # TODO: legacy
      '/_uploads/temp'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
infopark_fiona7-1.6.1.1.5 lib/fiona7/temporary_uploader.rb
infopark_fiona7-1.6.1.1.1 lib/fiona7/temporary_uploader.rb
infopark_fiona7-1.6.1.1.0 lib/fiona7/temporary_uploader.rb