File not uploading properly

View: New views
9 Messages — Rating Filter:   Alert me  

File not uploading properly

by Adam Akhtar-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi all,

I am using the following code to upload a file.

views:
<%= file_field "upload", 'file' ,:size=> '30' %>

controller:
file_path=
"#{RAILS_ROOT}/public/email_attachments/#{params[:upload][:file].original_filename}"
file = File.new(File.join(file_path), "wb")
file.write(params['file_' + i.to_s].read)

Next I am attaching the uploaded file and sending an email. Everything
is working fine.

BUT, If I attach a big size file or Image, the file will not be uploaded
completely. For Example If I upload a big image, I ll be able to see
only half of the image, can anyone tell me the reason and solution to
this problem.

Thanks in advance,
Raju
--
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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: File not uploading properly

by Bugzilla from leonardomateo@gmail.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Mon, Nov 2, 2009 at 9:43 AM, Raju Aralikatti
<rails-mailing-list@...> wrote:

>
> Hi all,
>
> I am using the following code to upload a file.
>
> views:
> <%= file_field "upload", 'file' ,:size=> '30' %>
>
> controller:
> file_path=
> "#{RAILS_ROOT}/public/email_attachments/#{params[:upload][:file].original_filename}"
> file = File.new(File.join(file_path), "wb")
> file.write(params['file_' + i.to_s].read)
>
> Next I am attaching the uploaded file and sending an email. Everything
> is working fine.
>
> BUT, If I attach a big size file or Image,
What exactly is a big size file? I mean, starting from what size is
considered big?

> the file will not be uploaded
> completely. For Example If I upload a big image, I ll be able to see
> only half of the image, can anyone tell me the reason and solution to
> this problem.
>
Maybe you're getting some timeout error?
Maybe you can try some plugin for file upload such as attachment_fu or
paperclip or anyone you like.
Is there any reason why you're not using some of this and doing the
file creation by hand?



--
Leonardo Mateo.
There's no place like ~

--~--~---------~--~----~------------~-------~--~----~
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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: File not uploading properly

by sami-23 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


which server are you using ... you can increase maximum file upload
size and
maximum execution time as well ... hope this may solve the problem

On Nov 2, 3:43 pm, Raju Aralikatti <rails-mailing-l...@...>
wrote:

> Hi all,
>
> I am using the following code to upload a file.
>
> views:
> <%= file_field "upload", 'file' ,:size=> '30' %>
>
> controller:
> file_path=
> "#{RAILS_ROOT}/public/email_attachments/#{params[:upload][:file].original_filename}"
> file = File.new(File.join(file_path), "wb")
> file.write(params['file_' + i.to_s].read)
>
> Next I am attaching the uploaded file and sending an email. Everything
> is working fine.
>
> BUT, If I attach a big size file or Image, the file will not be uploaded
> completely. For Example If I upload a big image, I ll be able to see
> only half of the image, can anyone tell me the reason and solution to
> this problem.
>
> Thanks in advance,
> Raju
> --
> 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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: File not uploading properly

by Adam Akhtar-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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

--
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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: File not uploading properly

by Frederick Cheung-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Nov 3, 5:50 am, Raju Aralikatti <rails-mailing-l...@...>
wrote:

>           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

>           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
>
> --
> 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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: File not uploading properly

by Adam Akhtar-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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
--
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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: File not uploading properly

by Frederick Cheung-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message




On Nov 3, 9:30 am, Raju Aralikatti <rails-mailing-l...@...>
wrote:

> 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
>
> Thanks,
> Raju
> --
> 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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: File not uploading properly

by Adam Akhtar-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


In ur form tab write this property =>
enctype="multipart/form-data"
--
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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: File not uploading properly

by Adam Akhtar-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Thanks for your help,

Its working fine now. I used attachment_fu plugin.

Thanks,
Raju
--
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@...
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---