bbenezech/papermill

Where can I specify allowed file types?

Closed this issue · 2 comments

I have a ticket model which will permit asset uploads (PDF, ZIP, DOC, XLS, etc). I do not have a model for the attachment.

class Ticket < ActiveRecord::Base
  papermill :attachments
end

I have the following line in config/initializers/papermill.rb:

:images_only => false,

I get the following growl feedback after the file has transferred:

36341.DOC
File is not one of the allowed file types.

I'm just wondering where I can explicitly permit certain extensions, or content types without having an attachment model?

I modified the set_papermill_inline_js method in form_builder.rb to get this to work. I changed the following line from:

file_types: "#{ options[:images_only] ? '*.jpg;*.jpeg;*.png;*.gif' : '' }",

to:

file_types: "#{ options[:images_only] ? '*.jpg;*.jpeg;*.png;*.gif' : '*.*' }",

It now works just fine.

I'm on a Mac, so not sure if this was an OSX specific issue or not. Let me know if there is some other way I should have fixed this - perhaps a config setting that I missed.

I just investigated this. Seems like a design bug, the error you get has nothing to do with SwfUpload and the file_types settings (who just set constraints on the file browser).
The problem lies with Paperclip, who doesn't support inherited settings.
The ImageAsset < PapermillAsset Paperclip validation creeped the superclass (PapermillAsset) validation. (at least for the demo)
Basically, looks like you can only have only one asset class used with Papermill :/

If you don't need the server side validation and can go with SwfUpload filters, you can just use :images_only or :swfupload => { :file_types => ".jpg;.xls" } for a narrower filtering.

I've included your fix anyway, maybe there is a SwfUpload side effect in your case?

Released in next gem within a few hours.