Hi all, I am using aaa for uploads (Upload model) of assets to a dir below public. I also need to save files, into the Upload model, which come as attachments by email. Is there a way I can ask aaa to save the attachment as if it was uploaded? TIA, bakki --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 8/23/07, Bakki Kudva <bakki.kudva-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi all, > > I am using aaa for uploads (Upload model) of assets to a dir below > public. I also need to save files, into the Upload model, which come > as attachments by email. Is there a way I can ask aaa to save the > attachment as if it was uploaded? TIA, > > bakkibakki, you should be loop through the email''s attachments and create new Uploads like this: for attachment in email.attachments Upload.create! attachment end # note: this is untested code, but should point you in the right direction. Have a look at this article regarding Action Mailer''s attachments: http://wiki.rubyonrails.org/rails/pages/HowToReceiveEmailsWithActionMailer --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thank you for your reply Sam, I don''t have my action mailer receive part working yet and I will try this when its done. However the Upload model has acts_as_attachment :storage => :file_system, :file_system_path => ''uploads'' validates_as_attachment I was wondering if acts_as_attachment can take an attachment passed to the model vs. the uploaded file which it normally gets from cgi param. I thought the validates_as_attachment call back might not work if the attachment was passed to the model as you suggest. I''ll have to look the aaa code over to see if this doesn''t work. -bakki On 8/23/07, Sam Morrison <sam-o6v14nQ79ppXqviUI+FSNg@public.gmane.org> wrote:> > On 8/23/07, Bakki Kudva <bakki.kudva-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi all, > > > > I am using aaa for uploads (Upload model) of assets to a dir below > > public. I also need to save files, into the Upload model, which come > > as attachments by email. Is there a way I can ask aaa to save the > > attachment as if it was uploaded? TIA, > > > > bakki > > bakki, > > you should be loop through the email''s attachments and create new > Uploads like this: > > for attachment in email.attachments > Upload.create! attachment > end > > # note: this is untested code, but should point you in the right direction. > > Have a look at this article regarding Action Mailer''s attachments: > > http://wiki.rubyonrails.org/rails/pages/HowToReceiveEmailsWithActionMailer > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
here''s a post on how to upload files stored locally: http://www.railsweenie.com/forums/2/topics/1013 On 8/23/07, Bakki Kudva <bakki.kudva-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Thank you for your reply Sam, I don''t have my action mailer receive > part working yet and I will try this when its done. However the > Upload model has > > acts_as_attachment :storage => :file_system, :file_system_path => ''uploads'' > validates_as_attachment > > I was wondering if acts_as_attachment can take an attachment passed to > the model vs. the uploaded file which it normally gets from cgi param. > I thought the validates_as_attachment call back might not work if the > attachment was passed to the model as you suggest. I''ll have to look > the aaa code over to see if this doesn''t work. > > -bakki > > On 8/23/07, Sam Morrison <sam-o6v14nQ79ppXqviUI+FSNg@public.gmane.org> wrote: > > > > On 8/23/07, Bakki Kudva <bakki.kudva-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Hi all, > > > > > > I am using aaa for uploads (Upload model) of assets to a dir below > > > public. I also need to save files, into the Upload model, which come > > > as attachments by email. Is there a way I can ask aaa to save the > > > attachment as if it was uploaded? TIA, > > > > > > bakki > > > > bakki, > > > > you should be loop through the email''s attachments and create new > > Uploads like this: > > > > for attachment in email.attachments > > Upload.create! attachment > > end > > > > # note: this is untested code, but should point you in the right direction. > > > > Have a look at this article regarding Action Mailer''s attachments: > > > > http://wiki.rubyonrails.org/rails/pages/HowToReceiveEmailsWithActionMailer > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hello, I am not sure if I understand correctly, but you can pass a regular file (on disk) to the model conviently using TestUploadedFile (see http://api.rubyonrails.org/classes/ActionController/TestUploadedFile.html#M000278) like this: Photo.create( :uploaded_data => ActionController::TestUploadedFile.new(file, ''image/jpeg'') ) See http://pastie.caboo.se/90597 for more complete code I use for importing whole directory of photos into application. (You can even use this in script/console or script/runner, thus automating the importing process.) Cheers, Karel On Aug 23, 5:28 pm, "Bakki Kudva" <bakki.ku...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I was wondering if acts_as_attachment can take an attachment passed to > the model vs. the uploaded file which it normally gets from cgi param.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Karel, This actually should work for me. I was looking at the code in acts_as_attachment and it has the following code which handles uploaded files. # This method handles the uploaded file object. If you set the field name to uploaded_data, you don''t need # any special code in your controller. # # <% form_for :attachment, :html => { :multipart => true } do |f| -%> # <p><%= f.file_field :uploaded_data %></p> # <p><%= submit_tag :Save %> # <% end -%> # # @attachment = Attachment.create! params[:attachment] def uploaded_data=(file_data) return nil if file_data.nil? || file_data.size == 0 self.content_type = file_data.content_type.strip self.filename = file_data.original_filename.strip self.attachment_data = file_data.read end So this should fire when, as you suggest Photo.create( :uploaded_data => ActionController::TestUploadedFile.new(file, ''image/jpeg'') ) :uploaded_data gets assigned to and the rest of aaa validations etc should work. Thank you for your help. -bakki On 8/24/07, Karel Minarik <karel.minarik-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hello, > > I am not sure if I understand correctly, but you can pass a regular > file (on disk) to the model conviently using TestUploadedFile (see > http://api.rubyonrails.org/classes/ActionController/TestUploadedFile.html#M000278) > like this: > > Photo.create( :uploaded_data => > ActionController::TestUploadedFile.new(file, ''image/jpeg'') ) > > See http://pastie.caboo.se/90597 for more complete code I use for > importing whole directory of photos into application. > > (You can even use this in script/console or script/runner, thus > automating the importing process.) > > Cheers, > > Karel > > > > On Aug 23, 5:28 pm, "Bakki Kudva" <bakki.ku...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I was wondering if acts_as_attachment can take an attachment passed to > > the model vs. the uploaded file which it normally gets from cgi param. > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hello, yes, that''s it precisely. I guess acts_as_attachment has `TestUploadedFile` somehow encapsulated, but I couldn''t get it to work, don''t recall precisely why. I recently used `TestUploadedFile` to import loads of legacy data into ported application with *great* results. Glad to help, cheers, Karel On Aug 24, 5:38 pm, "Bakki Kudva" <bakki.ku...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This actually should work for me. I was looking at the code in > acts_as_attachment and it has the following code which handles > uploaded files.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---