Roberto Gattinoni
2007-Sep-07 15:25 UTC
attachment_fu, PDF files and :db_file storage type
Problem:
- correctly uploading PDF files, PNG, JPEG and storing in MySQL dbase;
- when downloading (and it seems only with PDF files) with send_data and
saving on file system, consistently only 2kbyte of data are downloaded;
if alternatively :disposition => ''inline'' Adobe Reader
signals incorrect
file content.
Has anyone experienced the same problem and what can be wrong with the
following?
My migrations:
class CreateDocmetas < ActiveRecord::Migration
def self.up
create_table :docmeta do |t|
t.column :db_file_id, :integer
t.column :size, :integer, :null => false
t.column :content_type, :text, :null => false
t.column :filename, :text, :null => false
t.column :height, :integer
t.column :width, :integer
t.column :parent_id, :integer
t.column :thumbnail, :text
end
end
def self.down
drop_table :docmeta
end
end
class CreateDbFiles < ActiveRecord::Migration
def self.up
create_table :db_file do |t|
t.column :data, :binary
end
end
def self.down
drop_table :db_file
end
end
My models:
class Docmeta < ActiveRecord::Base
set_table_name ''docmeta''
belongs_to :db_file
has_attachment :storage => :db_file,
:min_size => 1.kilobyte,
:max_size => 10.megabytes
validates_as_attachment
end
class DbFile < ActiveRecord::Base
set_table_name ''db_file''
end
My controller (only for the download action):
def view
@attachment = Attachment.find(params[:attchid])
if @attachment
send_data @attachment.docmeta.db_file.data,
:filename => @attachment.docmeta.filename,
:type => @attachment.docmeta.content_type,
:disposition => ''attachment''
end
end
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
When you create a column with binary file type, Rails automatically converts it to mysql type blob. By default blob type is 2kb. Use t.column data, :binary, :limit => 10.megabyte in your migration to set the correct size of the mysql blob. - Tushar On Sep 7, 8:25 am, Roberto Gattinoni <rails-mailing-l...@andreas- s.net> wrote:> Problem: > - correctly uploading PDF files, PNG, JPEG and storing in MySQL dbase; > - when downloading (and it seems only with PDF files) with send_data and > saving on file system, consistently only 2kbyte of data are downloaded; > if alternatively :disposition => ''inline'' Adobe Reader signals incorrect > file content. > > Has anyone experienced the same problem and what can be wrong with the > following? > > My migrations: > > class CreateDocmetas < ActiveRecord::Migration > def self.up > create_table :docmeta do |t| > t.column :db_file_id, :integer > t.column :size, :integer, :null => false > t.column :content_type, :text, :null => false > t.column :filename, :text, :null => false > t.column :height, :integer > t.column :width, :integer > t.column :parent_id, :integer > t.column :thumbnail, :text > end > end > > def self.down > drop_table :docmeta > end > end > > class CreateDbFiles < ActiveRecord::Migration > def self.up > create_table :db_file do |t| > t.column :data, :binary > end > end > > def self.down > drop_table :db_file > end > end > > My models: > > class Docmeta < ActiveRecord::Base > set_table_name ''docmeta'' > > belongs_to :db_file > > has_attachment :storage => :db_file, > :min_size => 1.kilobyte, > :max_size => 10.megabytes > > validates_as_attachment > > end > > class DbFile < ActiveRecord::Base > set_table_name ''db_file'' > end > > My controller (only for the download action): > > def view > @attachment = Attachment.find(params[:attchid]) > if @attachment > send_data @attachment.docmeta.db_file.data, > :filename => @attachment.docmeta.filename, > :type => @attachment.docmeta.content_type, > :disposition => ''attachment'' > end > end > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---