which server are you using ... you can increase maximum file upload size and maximum execution time as well ... hope this may solve the problem
Thanks a lot for your reply,
I have used multiple file upload here is the view part.
<%= file_field "upload", 'file' ,:size=> '30', :style=> 'color:red;'%><br />
Attached Files <input type='hidden' name='file_nos' id='file_counter'> <div id="files_list" style='display:none;' class='files_list_class'> <script> var multi_selector = new MultiSelector( document.getElementById('files_list'), 5 ); multi_selector.addElement( document.getElementById('upload_file') ); </script> </div>
and javascript.
when it goes to the action I will be getting the files attached in params[:file_1], params[:file_2]...... etc. params["file_nos"] is number of files being uploaded and thus it should loop that many times.
The controller goes like this:
params["file_nos"].to_i.times do |i| if params['file_'+i.to_s].to_s != "" || params['file_'+i.to_s] != nil #begin @email_attachment = SupportEmailAttachment.new @email_attachment.filename = params['file_' + i.to_s].original_filename @email_attachment.save file_path= "#{RAILS_ROOT}/public/email_attachments/#{params['file_' + i.to_s].original_filename}" file = File.new(File.join(file_path), "wb") file.write(params['file_' + i.to_s].read) file_path_array << file_path #rescue #end end end Mailer.deliver_create_ticket user_email,file_path_array
After the files are uploaded I am attaching all the files in the mail and sending them.
So here is my problem,
1. The files attached in the mails are not complete. ie if i have upload any file, there will be all attachments but they wont open, some images uploaded will display only half.
I am using apache + mongrel congiguration.
Please help me its urgent.
Thanks, Raju
file = File\.new\(File\.join\(file\_path\), "wb"\) file\.write\(params\['file\_' \+ i\.to\_s\]\.read\)
You're not closing the file you create, which could conceivably cause problems (if you use the block form of File.open you don't need to worry about that)
Fred
Thanks for your reply fred,
file = File.new(File.join(file_path), "wb") file.write(params['file_' + i.to_s].read)
You mean to say my code must be like this,
file = File.new(File.join(file_path), "wb") file.write(params['file_' + i.to_s].read) file.close
But I am not getting the attachments properly in my email. If you can send your email ID I will send an email to you through my app, so that you can tell me what is the problem
Thanks, Raju
Thanks for your reply fred,
file = File.new(File.join(file_path), "wb") file.write(params['file_' + i.to_s].read)
You mean to say my code must be like this,
file = File.new(File.join(file_path), "wb") file.write(params['file_' + i.to_s].read) file.close
yup, something like that.
File.open(path, 'wb') do |file| file.write(...) end
is nicer because it ensures the file gets closed (obviously you could replicate this yourself but File.open already does it so not much point)
But I am not getting the attachments properly in my email. If you can send your email ID I will send an email to you through my app, so that you can tell me what is the problem
Sounds like you need to isolate the problem: is the mailer fine but it is being given half uploaded files, or is the uploading part happening file but the mailer is ok?
Fred