Sha256: d263801ef74f90c17d74eea85dee761a7ffe6a5964541e3a639453c14d5ca146

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

begin
    require 'ftools'
rescue LoadError
end

module Spider; module Forms
    
    class FileInput < Input
        tag 'file'
        is_attr_accessor :save_path, :type => String, :default => Proc.new{ Spider.paths[:var]+'/data/uploaded_files' }
        
        def needs_multipart?
            true
        end
        
        def prepare
            raise "No save path defined" unless @save_path
            raise "Save path #{@save_path} is not a directory" unless File.directory?(File.dirname(@save_path))
            FileUtils.mkdir_p(@save_path) unless File.directory?(@save_path)

            super
        end
        
        
        def prepare_value(val)
            return nil if !val || val.empty?
            if val['file'] && !val['file'].is_a?(String)
                dest_path = @save_path+'/'+val['file'].filename
                FileUtils.copy(val['file'].path, dest_path)
                return dest_path
            elsif val['clear']
                self.value = nil
                return
            end
            return @value
        end
        
        __.action
        def view_file
            raise NotFound.new(@value.to_s) unless @value && @value.file?
            @response.headers['Content-Description'] = 'File Transfer'
            @response.headers['Content-Disposition'] = "attachment; filename=\"#{@value.basename}\""
            output_static(@value.to_s)
        end
        
    end
    
end; end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spiderfw-0.6.37 apps/core/forms/widgets/inputs/file_input/file_input.rb
spiderfw-0.6.35 apps/core/forms/widgets/inputs/file_input/file_input.rb
spiderfw-0.6.34 apps/core/forms/widgets/inputs/file_input/file_input.rb
spiderfw-0.6.33 apps/core/forms/widgets/inputs/file_input/file_input.rb