[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

problems about uploading file

???

1/3/2008 3:48:00 AM

Hi guys,
I am working on some upload file code , here it is :
================== code begin =================
require 'fileutils'
require 'uuid'
class Content < ActiveRecord::Base
include FileUtils
include UUID
before_create :write_file_to_disk
before_update :write_file_to_disk

......... ................

def update_attributes_from_params params, *args
args.each do |attribute|
s= params[attribute].blank? ? "self.#{attribute.to_s}=%Q{}"
:

%Q{self.#{attribute.to_s}="#{params[attribute]}"}
eval(s)
end
update
end
......... ..............

private

def write_file_to_disk
file_path = "#{upload_file_path}/#{user_id}/#{file_name}"
p " the file size : #{file.size}"
File.open(file_path, "wb") do |media_file|
media_file.write file.read
end
self.size = @file.size
end

def file= file
return if file.blank?
@file = file
ext_name = File.extname file.original_filename
# original_file_name and file_name are both content attributes
original_file_name = file.original_filename
file_name = UUID.new + ext_name
end

end

when I update an file, I do it like this :
@content = Content.find params[:content_id]
@content.update_attributes_from_params params, :title, :orginazation, :file

and it produces :
"the file size : 8477823"

but when I check the file uploaded ,
irb >> File.size"/home/tim/upload_test/1/adb12d60-9bd5-012a-a458-000c29f18cec.mp3"
=> 2176
it's only 2.1K, so any body can tell me why and how to handel it correctly.
I tried @content.send("file=",params[:file]),but the real size is still 2176.

Thanks, regards!

Tim

1 Answer

Andrew Stewart

1/3/2008 4:15:00 PM

0


On 3 Jan 2008, at 03:47, =E6=BB=95=E7=A5=A5=E5=8A=9F wrote:

> I am working on some upload file code , here it is :


It looks like you're using Rails, in which case you might save =20
yourself some work with the attachment_fu plugin:

http://svn.techno-weenie.net/projects/plugins/atta...

And if you are using Rails you'll probably receive more responses on =20
the Rails mailing list:

http://groups.google.com/group/rubyon...

Sorry not to have answered your question directly!

Regards,
Andy Stewart

-------
http://airbladeso...