futuresinc-attachment_fu 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. data/VERSION.yml +1 -1
  2. data/attachment_fu.gemspec +11 -11
  3. data/init.rb +1 -1
  4. data/lib/attachment_fu/backends/cloud_file_backend.rb +209 -0
  5. data/lib/attachment_fu/backends/db_file_backend.rb +37 -0
  6. data/lib/attachment_fu/backends/file_system_backend.rb +124 -0
  7. data/lib/attachment_fu/backends/s3_backend.rb +392 -0
  8. data/lib/attachment_fu/processors/core_image_processor.rb +55 -0
  9. data/lib/attachment_fu/processors/gd2_processor.rb +53 -0
  10. data/lib/attachment_fu/processors/image_science_processor.rb +60 -0
  11. data/lib/attachment_fu/processors/mini_magick_processor.rb +131 -0
  12. data/lib/attachment_fu/processors/rmagick_processor.rb +56 -0
  13. data/lib/attachment_fu.rb +543 -0
  14. data/test/backends/remote/cloudfiles_test.rb +3 -3
  15. data/test/backends/remote/s3_test.rb +3 -3
  16. data/test/basic_test.rb +2 -2
  17. data/test/extra_attachment_test.rb +2 -2
  18. metadata +11 -11
  19. data/lib/technoweenie/attachment_fu/backends/cloud_file_backend.rb +0 -211
  20. data/lib/technoweenie/attachment_fu/backends/db_file_backend.rb +0 -39
  21. data/lib/technoweenie/attachment_fu/backends/file_system_backend.rb +0 -126
  22. data/lib/technoweenie/attachment_fu/backends/s3_backend.rb +0 -394
  23. data/lib/technoweenie/attachment_fu/processors/core_image_processor.rb +0 -59
  24. data/lib/technoweenie/attachment_fu/processors/gd2_processor.rb +0 -54
  25. data/lib/technoweenie/attachment_fu/processors/image_science_processor.rb +0 -61
  26. data/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb +0 -132
  27. data/lib/technoweenie/attachment_fu/processors/rmagick_processor.rb +0 -57
  28. data/lib/technoweenie/attachment_fu.rb +0 -545
@@ -1,545 +0,0 @@
1
- require 'tempfile'
2
- require 'geometry'
3
-
4
- Tempfile.class_eval do
5
- # overwrite so tempfiles use the extension of the basename. important for rmagick and image science
6
- def make_tmpname(basename, n)
7
- ext = nil
8
- sprintf("%s%d-%d%s", basename.to_s.gsub(/\.\w+$/) { |s| ext = s; '' }, $$, n, ext)
9
- end
10
- end
11
-
12
- module Technoweenie # :nodoc:
13
- module AttachmentFu # :nodoc:
14
- @@default_processors = %w(ImageScience Rmagick MiniMagick Gd2 CoreImage)
15
- @@tempfile_path = File.join(RAILS_ROOT, 'tmp', 'attachment_fu')
16
- @@content_types = [
17
- 'image/jpeg',
18
- 'image/pjpeg',
19
- 'image/jpg',
20
- 'image/gif',
21
- 'image/png',
22
- 'image/x-png',
23
- 'image/jpg',
24
- 'image/x-ms-bmp',
25
- 'image/bmp',
26
- 'image/x-bmp',
27
- 'image/x-bitmap',
28
- 'image/x-xbitmap',
29
- 'image/x-win-bitmap',
30
- 'image/x-windows-bmp',
31
- 'image/ms-bmp',
32
- 'application/bmp',
33
- 'application/x-bmp',
34
- 'application/x-win-bitmap',
35
- 'application/preview',
36
- 'image/jp_',
37
- 'application/jpg',
38
- 'application/x-jpg',
39
- 'image/pipeg',
40
- 'image/vnd.swiftview-jpeg',
41
- 'image/x-xbitmap',
42
- 'application/png',
43
- 'application/x-png',
44
- 'image/gi_',
45
- 'image/x-citrix-pjpeg'
46
- ]
47
- mattr_reader :content_types, :tempfile_path, :default_processors
48
- mattr_writer :tempfile_path
49
-
50
- class ThumbnailError < StandardError; end
51
- class AttachmentError < StandardError; end
52
-
53
- module ActMethods
54
- # Options:
55
- # * <tt>:content_type</tt> - Allowed content types. Allows all by default. Use :image to allow all standard image types.
56
- # * <tt>:min_size</tt> - Minimum size allowed. 1 byte is the default.
57
- # * <tt>:max_size</tt> - Maximum size allowed. 1.megabyte is the default.
58
- # * <tt>:size</tt> - Range of sizes allowed. (1..1.megabyte) is the default. This overrides the :min_size and :max_size options.
59
- # * <tt>:resize_to</tt> - Used by RMagick to resize images. Pass either an array of width/height, or a geometry string.
60
- # * <tt>:thumbnails</tt> - Specifies a set of thumbnails to generate. This accepts a hash of filename suffixes and RMagick resizing options.
61
- # * <tt>:thumbnail_class</tt> - Set what class to use for thumbnails. This attachment class is used by default.
62
- # * <tt>:path_prefix</tt> - path to store the uploaded files. Uses public/#{table_name} by default for the filesystem, and just #{table_name}
63
- # for the S3 backend. Setting this sets the :storage to :file_system.
64
-
65
- # * <tt>:storage</tt> - Use :file_system to specify the attachment data is stored with the file system. Defaults to :db_system.
66
- # * <tt>:cloundfront</tt> - Set to true if you are using S3 storage and want to serve the files through CloudFront. You will need to
67
- # set a distribution domain in the amazon_s3.yml config file. Defaults to false
68
- # * <tt>:bucket_key</tt> - Use this to specify a different bucket key other than :bucket_name in the amazon_s3.yml file. This allows you to use
69
- # different buckets for different models. An example setting would be :image_bucket and the you would need to define the name of the corresponding
70
- # bucket in the amazon_s3.yml file.
71
-
72
- # * <tt>:keep_profile</tt> By default image EXIF data will be stripped to minimize image size. For small thumbnails this proivides important savings. Picture quality is not affected. Set to false if you want to keep the image profile as is. ImageScience will allways keep EXIF data.
73
- #
74
- # Examples:
75
- # has_attachment :max_size => 1.kilobyte
76
- # has_attachment :size => 1.megabyte..2.megabytes
77
- # has_attachment :content_type => 'application/pdf'
78
- # has_attachment :content_type => ['application/pdf', 'application/msword', 'text/plain']
79
- # has_attachment :content_type => :image, :resize_to => [50,50]
80
- # has_attachment :content_type => ['application/pdf', :image], :resize_to => 'x50'
81
- # has_attachment :thumbnails => { :thumb => [50, 50], :geometry => 'x50' }
82
- # has_attachment :storage => :file_system, :path_prefix => 'public/files'
83
- # has_attachment :storage => :file_system, :path_prefix => 'public/files',
84
- # :content_type => :image, :resize_to => [50,50]
85
- # has_attachment :storage => :file_system, :path_prefix => 'public/files',
86
- # :thumbnails => { :thumb => [50, 50], :geometry => 'x50' }
87
- # has_attachment :storage => :s3
88
- def has_attachment(options = {})
89
- # this allows you to redefine the acts' options for each subclass, however
90
- options[:min_size] ||= 1
91
- options[:max_size] ||= 1.megabyte
92
- options[:size] ||= (options[:min_size]..options[:max_size])
93
- options[:thumbnails] ||= {}
94
- options[:thumbnail_class] ||= self
95
- options[:s3_access] ||= :public_read
96
- options[:cloudfront] ||= false
97
- options[:content_type] = [options[:content_type]].flatten.collect! { |t| t == :image ? Technoweenie::AttachmentFu.content_types : t }.flatten unless options[:content_type].nil?
98
-
99
- unless options[:thumbnails].is_a?(Hash)
100
- raise ArgumentError, ":thumbnails option should be a hash: e.g. :thumbnails => { :foo => '50x50' }"
101
- end
102
-
103
- extend ClassMethods unless (class << self; included_modules; end).include?(ClassMethods)
104
- include InstanceMethods unless included_modules.include?(InstanceMethods)
105
-
106
- parent_options = attachment_options || {}
107
- # doing these shenanigans so that #attachment_options is available to processors and backends
108
- self.attachment_options = options
109
-
110
- attr_accessor :thumbnail_resize_options
111
-
112
- attachment_options[:storage] ||= (attachment_options[:file_system_path] || attachment_options[:path_prefix]) ? :file_system : :db_file
113
- attachment_options[:storage] ||= parent_options[:storage]
114
- attachment_options[:path_prefix] ||= attachment_options[:file_system_path]
115
- if attachment_options[:path_prefix].nil?
116
- attachment_options[:path_prefix] = case attachment_options[:storage]
117
- when :s3 then table_name
118
- when :cloud_files then table_name
119
- else File.join("public", table_name)
120
- end
121
- end
122
- attachment_options[:path_prefix] = attachment_options[:path_prefix][1..-1] if options[:path_prefix].first == '/'
123
-
124
- association_options = { :foreign_key => 'parent_id' }
125
- if attachment_options[:association_options]
126
- association_options.merge!(attachment_options[:association_options])
127
- end
128
- with_options(association_options) do |m|
129
- m.has_many :thumbnails, :class_name => "::#{attachment_options[:thumbnail_class]}"
130
- m.belongs_to :parent, :class_name => "::#{base_class}" unless options[:thumbnails].empty?
131
- end
132
-
133
- storage_mod = Technoweenie::AttachmentFu::Backends.const_get("#{options[:storage].to_s.classify}Backend")
134
- include storage_mod unless included_modules.include?(storage_mod)
135
-
136
- case attachment_options[:processor]
137
- when :none, nil
138
- processors = Technoweenie::AttachmentFu.default_processors.dup
139
- begin
140
- if processors.any?
141
- attachment_options[:processor] = processors.first
142
- processor_mod = Technoweenie::AttachmentFu::Processors.const_get("#{attachment_options[:processor].to_s.classify}Processor")
143
- include processor_mod unless included_modules.include?(processor_mod)
144
- end
145
- rescue Object, Exception
146
- raise unless load_related_exception?($!)
147
-
148
- processors.shift
149
- retry
150
- end
151
- else
152
- begin
153
- processor_mod = Technoweenie::AttachmentFu::Processors.const_get("#{attachment_options[:processor].to_s.classify}Processor")
154
- include processor_mod unless included_modules.include?(processor_mod)
155
- rescue Object, Exception
156
- raise unless load_related_exception?($!)
157
-
158
- puts "Problems loading #{options[:processor]}Processor: #{$!}"
159
- end
160
- end unless parent_options[:processor] # Don't let child override processor
161
- end
162
-
163
- def load_related_exception?(e) #:nodoc: implementation specific
164
- case
165
- when e.kind_of?(LoadError), e.kind_of?(MissingSourceFile), $!.class.name == "CompilationError"
166
- # We can't rescue CompilationError directly, as it is part of the RubyInline library.
167
- # We must instead rescue RuntimeError, and check the class' name.
168
- true
169
- else
170
- false
171
- end
172
- end
173
- private :load_related_exception?
174
- end
175
-
176
- module ClassMethods
177
- delegate :content_types, :to => Technoweenie::AttachmentFu
178
-
179
- # Performs common validations for attachment models.
180
- def validates_as_attachment
181
- validates_presence_of :size, :content_type, :filename
182
- validate :attachment_attributes_valid?
183
- end
184
-
185
- # Returns true or false if the given content type is recognized as an image.
186
- def image?(content_type)
187
- content_types.include?(content_type)
188
- end
189
-
190
- def self.extended(base)
191
- base.class_inheritable_accessor :attachment_options
192
- base.before_destroy :destroy_thumbnails
193
- base.before_validation :set_size_from_temp_path
194
- base.after_save :after_process_attachment
195
- base.after_destroy :destroy_file
196
- base.after_validation :process_attachment
197
- if defined?(::ActiveSupport::Callbacks)
198
- base.define_callbacks :after_resize, :after_attachment_saved, :before_thumbnail_saved
199
- end
200
- end
201
-
202
- unless defined?(::ActiveSupport::Callbacks)
203
- # Callback after an image has been resized.
204
- #
205
- # class Foo < ActiveRecord::Base
206
- # acts_as_attachment
207
- # after_resize do |record, img|
208
- # record.aspect_ratio = img.columns.to_f / img.rows.to_f
209
- # end
210
- # end
211
- def after_resize(&block)
212
- write_inheritable_array(:after_resize, [block])
213
- end
214
-
215
- # Callback after an attachment has been saved either to the file system or the DB.
216
- # Only called if the file has been changed, not necessarily if the record is updated.
217
- #
218
- # class Foo < ActiveRecord::Base
219
- # acts_as_attachment
220
- # after_attachment_saved do |record|
221
- # ...
222
- # end
223
- # end
224
- def after_attachment_saved(&block)
225
- write_inheritable_array(:after_attachment_saved, [block])
226
- end
227
-
228
- # Callback before a thumbnail is saved. Use this to pass any necessary extra attributes that may be required.
229
- #
230
- # class Foo < ActiveRecord::Base
231
- # acts_as_attachment
232
- # before_thumbnail_saved do |thumbnail|
233
- # record = thumbnail.parent
234
- # ...
235
- # end
236
- # end
237
- def before_thumbnail_saved(&block)
238
- write_inheritable_array(:before_thumbnail_saved, [block])
239
- end
240
- end
241
-
242
- # Get the thumbnail class, which is the current attachment class by default.
243
- # Configure this with the :thumbnail_class option.
244
- def thumbnail_class
245
- attachment_options[:thumbnail_class] = attachment_options[:thumbnail_class].constantize unless attachment_options[:thumbnail_class].is_a?(Class)
246
- attachment_options[:thumbnail_class]
247
- end
248
-
249
- # Copies the given file path to a new tempfile, returning the closed tempfile.
250
- def copy_to_temp_file(file, temp_base_name)
251
- returning Tempfile.new(temp_base_name, Technoweenie::AttachmentFu.tempfile_path) do |tmp|
252
- tmp.close
253
- FileUtils.cp file, tmp.path
254
- end
255
- end
256
-
257
- # Writes the given data to a new tempfile, returning the closed tempfile.
258
- def write_to_temp_file(data, temp_base_name)
259
- returning Tempfile.new(temp_base_name, Technoweenie::AttachmentFu.tempfile_path) do |tmp|
260
- tmp.binmode
261
- tmp.write data
262
- tmp.close
263
- end
264
- end
265
- end
266
-
267
- module InstanceMethods
268
- def self.included(base)
269
- base.define_callbacks *[:after_resize, :after_attachment_saved, :before_thumbnail_saved] if base.respond_to?(:define_callbacks)
270
- end
271
-
272
- # Checks whether the attachment's content type is an image content type
273
- def image?
274
- self.class.image?(content_type)
275
- end
276
-
277
- # Returns true/false if an attachment is thumbnailable. A thumbnailable attachment has an image content type and the parent_id attribute.
278
- def thumbnailable?
279
- image? && respond_to?(:parent_id) && parent_id.nil?
280
- end
281
-
282
- # Returns the class used to create new thumbnails for this attachment.
283
- def thumbnail_class
284
- self.class.thumbnail_class
285
- end
286
-
287
- # Gets the thumbnail name for a filename. 'foo.jpg' becomes 'foo_thumbnail.jpg'
288
- def thumbnail_name_for(thumbnail = nil)
289
- return filename if thumbnail.blank?
290
- ext = nil
291
- basename = filename.gsub /\.\w+$/ do |s|
292
- ext = s; ''
293
- end
294
- # ImageScience doesn't create gif thumbnails, only pngs
295
- ext.sub!(/gif$/, 'png') if attachment_options[:processor] == "ImageScience"
296
- "#{basename}_#{thumbnail}#{ext}"
297
- end
298
-
299
- # Creates or updates the thumbnail for the current attachment.
300
- def create_or_update_thumbnail(temp_file, file_name_suffix, *size)
301
- thumbnailable? || raise(ThumbnailError.new("Can't create a thumbnail if the content type is not an image or there is no parent_id column"))
302
- returning find_or_initialize_thumbnail(file_name_suffix) do |thumb|
303
- thumb.temp_paths.unshift temp_file
304
- thumb.send(:'attributes=', {
305
- :content_type => content_type,
306
- :filename => thumbnail_name_for(file_name_suffix),
307
- :thumbnail_resize_options => size
308
- }, false)
309
- callback_with_args :before_thumbnail_saved, thumb
310
- thumb.save!
311
- end
312
- end
313
-
314
- # Sets the content type.
315
- def content_type=(new_type)
316
- write_attribute :content_type, new_type.to_s.strip
317
- end
318
-
319
- # Sanitizes a filename.
320
- def filename=(new_name)
321
- write_attribute :filename, sanitize_filename(new_name)
322
- end
323
-
324
- # Returns the width/height in a suitable format for the image_tag helper: (100x100)
325
- def image_size
326
- [width.to_s, height.to_s] * 'x'
327
- end
328
-
329
- # Returns true if the attachment data will be written to the storage system on the next save
330
- def save_attachment?
331
- File.file?(temp_path.to_s)
332
- end
333
-
334
- # nil placeholder in case this field is used in a form.
335
- def uploaded_data() nil; end
336
-
337
- # This method handles the uploaded file object. If you set the field name to uploaded_data, you don't need
338
- # any special code in your controller.
339
- #
340
- # <% form_for :attachment, :html => { :multipart => true } do |f| -%>
341
- # <p><%= f.file_field :uploaded_data %></p>
342
- # <p><%= submit_tag :Save %>
343
- # <% end -%>
344
- #
345
- # @attachment = Attachment.create! params[:attachment]
346
- #
347
- # TODO: Allow it to work with Merb tempfiles too.
348
- def uploaded_data=(file_data)
349
- if file_data.respond_to?(:content_type)
350
- return nil if file_data.size == 0
351
- self.content_type = detect_mimetype(file_data)
352
- self.filename = file_data.original_filename if respond_to?(:filename)
353
- else
354
- return nil if file_data.blank? || file_data['size'] == 0
355
- self.content_type = file_data['content_type']
356
- self.filename = file_data['filename']
357
- file_data = file_data['tempfile']
358
- end
359
- if file_data.is_a?(StringIO)
360
- file_data.rewind
361
- set_temp_data file_data.read
362
- else
363
- self.temp_paths.unshift file_data
364
- end
365
- end
366
-
367
- # Gets the latest temp path from the collection of temp paths. While working with an attachment,
368
- # multiple Tempfile objects may be created for various processing purposes (resizing, for example).
369
- # An array of all the tempfile objects is stored so that the Tempfile instance is held on to until
370
- # it's not needed anymore. The collection is cleared after saving the attachment.
371
- def temp_path
372
- p = temp_paths.first
373
- p.respond_to?(:path) ? p.path : p.to_s
374
- end
375
-
376
- # Gets an array of the currently used temp paths. Defaults to a copy of #full_filename.
377
- def temp_paths
378
- @temp_paths ||= (new_record? || !respond_to?(:full_filename) || !File.exist?(full_filename) ?
379
- [] : [copy_to_temp_file(full_filename)])
380
- end
381
-
382
- # Gets the data from the latest temp file. This will read the file into memory.
383
- def temp_data
384
- save_attachment? ? File.read(temp_path) : nil
385
- end
386
-
387
- # Writes the given data to a Tempfile and adds it to the collection of temp files.
388
- def set_temp_data(data)
389
- temp_paths.unshift write_to_temp_file data unless data.nil?
390
- end
391
-
392
- # Copies the given file to a randomly named Tempfile.
393
- def copy_to_temp_file(file)
394
- self.class.copy_to_temp_file file, random_tempfile_filename
395
- end
396
-
397
- # Writes the given file to a randomly named Tempfile.
398
- def write_to_temp_file(data)
399
- self.class.write_to_temp_file data, random_tempfile_filename
400
- end
401
-
402
- # Stub for creating a temp file from the attachment data. This should be defined in the backend module.
403
- def create_temp_file() end
404
-
405
- # Allows you to work with a processed representation (RMagick, ImageScience, etc) of the attachment in a block.
406
- #
407
- # @attachment.with_image do |img|
408
- # self.data = img.thumbnail(100, 100).to_blob
409
- # end
410
- #
411
- def with_image(&block)
412
- self.class.with_image(temp_path, &block)
413
- end
414
-
415
- protected
416
- # Generates a unique filename for a Tempfile.
417
- def random_tempfile_filename
418
- "#{rand Time.now.to_i}#{filename || 'attachment'}"
419
- end
420
-
421
- def sanitize_filename(filename)
422
- return unless filename
423
- returning filename.strip do |name|
424
- # NOTE: File.basename doesn't work right with Windows paths on Unix
425
- # get only the filename, not the whole path
426
- name.gsub! /^.*(\\|\/)/, ''
427
-
428
- # Replace all non alphanumeric, underscore or periods with underscore
429
- name.gsub! /[^A-Za-z0-9\.\-]/, '_'
430
-
431
- # Remove multiple underscores
432
- name.gsub! /\_+/, '_'
433
-
434
- # Finally, downcase result including extension
435
- name.downcase!
436
- end
437
- end
438
-
439
- # before_validation callback.
440
- def set_size_from_temp_path
441
- self.size = File.size(temp_path) if save_attachment?
442
- end
443
-
444
- # validates the size and content_type attributes according to the current model's options
445
- def attachment_attributes_valid?
446
- [:size, :content_type].each do |attr_name|
447
- enum = attachment_options[attr_name]
448
- if Object.const_defined?(:I18n) # Rails >= 2.2
449
- errors.add attr_name, I18n.translate("activerecord.errors.messages.inclusion", attr_name => enum) unless enum.nil? || enum.include?(send(attr_name))
450
- else
451
- errors.add attr_name, ActiveRecord::Errors.default_error_messages[:inclusion] unless enum.nil? || enum.include?(send(attr_name))
452
- end
453
- end
454
- end
455
-
456
- # Initializes a new thumbnail with the given suffix.
457
- def find_or_initialize_thumbnail(file_name_suffix)
458
- respond_to?(:parent_id) ?
459
- thumbnail_class.find_or_initialize_by_thumbnail_and_parent_id(file_name_suffix.to_s, id) :
460
- thumbnail_class.find_or_initialize_by_thumbnail(file_name_suffix.to_s)
461
- end
462
-
463
- # Stub for a #process_attachment method in a processor
464
- def process_attachment
465
- @saved_attachment = save_attachment?
466
- end
467
-
468
- # Cleans up after processing. Thumbnails are created, the attachment is stored to the backend, and the temp_paths are cleared.
469
- def after_process_attachment
470
- if @saved_attachment
471
- if respond_to?(:process_attachment_with_processing) && thumbnailable? && !attachment_options[:thumbnails].blank? && parent_id.nil?
472
- temp_file = temp_path || create_temp_file
473
- attachment_options[:thumbnails].each { |suffix, size| create_or_update_thumbnail(temp_file, suffix, *size) }
474
- end
475
- save_to_storage
476
- @temp_paths.clear
477
- @saved_attachment = nil
478
- callback :after_attachment_saved
479
- end
480
- end
481
-
482
- # Resizes the given processed img object with either the attachment resize options or the thumbnail resize options.
483
- def resize_image_or_thumbnail!(img)
484
- if (!respond_to?(:parent_id) || parent_id.nil?) && attachment_options[:resize_to] # parent image
485
- resize_image(img, attachment_options[:resize_to])
486
- elsif thumbnail_resize_options # thumbnail
487
- resize_image(img, thumbnail_resize_options)
488
- end
489
- end
490
-
491
- # Yanked from ActiveRecord::Callbacks, modified so I can pass args to the callbacks besides self.
492
- # Only accept blocks, however
493
- if ActiveSupport.const_defined?(:Callbacks)
494
- # Rails 2.1 and beyond!
495
- def callback_with_args(method, arg = self)
496
- notify(method)
497
-
498
- result = run_callbacks(method, { :object => [self, arg] }) { |result, object| result == false }
499
-
500
- if result != false && respond_to_without_attributes?(method)
501
- result = send(method)
502
- end
503
-
504
- result
505
- end
506
-
507
- def run_callbacks(kind, options = {}, &block)
508
- options.reverse_merge!( :object => self )
509
- self.class.send("#{kind}_callback_chain").run(options[:object], options, &block)
510
- end
511
- else
512
- # Rails 2.0
513
- def callback_with_args(method, arg = self)
514
- notify(method)
515
-
516
- result = nil
517
- callbacks_for(method).each do |callback|
518
- result = callback.call(self, arg)
519
- return false if result == false
520
- end
521
- result
522
- end
523
- end
524
-
525
- # Removes the thumbnails for the attachment, if it has any
526
- def destroy_thumbnails
527
- self.thumbnails.each { |thumbnail| thumbnail.destroy } if thumbnailable?
528
- end
529
-
530
- def detect_mimetype(file_data)
531
- if file_data.content_type.strip == "application/octet-stream"
532
- return File.mime_type?(file_data.original_filename)
533
- else
534
- return file_data.content_type
535
- end
536
- end
537
- end
538
- end
539
- end
540
-
541
- ActiveRecord::Base.send(:extend, Technoweenie::AttachmentFu::ActMethods)
542
- Technoweenie::AttachmentFu.tempfile_path = ATTACHMENT_FU_TEMPFILE_PATH if Object.const_defined?(:ATTACHMENT_FU_TEMPFILE_PATH)
543
- FileUtils.mkdir_p Technoweenie::AttachmentFu.tempfile_path
544
-
545
- $:.unshift(File.dirname(__FILE__) + '../../vendor')