Hi all, I''ve tried very hard to understand file_field and how to determine local_path. However, I''m running into some issues and I believe it''s probably due to the different behaviors of file_field and local_path together. First, here''s my issue. I''m successfully parsing a yaml file using the following code (supplying only what''s necessary here): http://gist.github.com/276841 I''ll describe what I''m doing step by step and what I''ve accomplished so far. (The Task) Admin user wants to upload a new theme. A new theme houses the following file/directory structure: -- blue_lagoon (folder and the theme name) | -- images (folder) -- javascripts (folder) -- layouts (folder) -- stylesheets (folder) -- swfs (folder) blue_lagoon.yml (yaml config file that houses some information) 1. Admin user goes to themes index and clicks new. (working) 2. Admin user clicks browse and selects the blue_lagoon.yml file. (working) 3. Admin user clicks upload. (working) 4. Many validation checks are performed to ensure that a yml file is being selected, and that it contains all of the pertinent information. If it fails validation, notifications are sent to the admin user. (working) 5. Once everything is validated, the yml file is moved by rails to a temporary folder and parsed. The information is then stored in a merged parameter and sent to the model to be saved. (working) 6. The theme model now contains a complete record of the blue_lagoon.yml file. (working) ----- so far so good ----- here is where I''m running into some issues now 7. Now I want to call an after_save method that will dir glob the location that the (original) blue_lagoon.yml file was uploaded from, and begin to mass create and upload the information to the public/themes folder. The problem is I don''t know how to find the local_path to the current upload because rails moved it to the temp folder. If I try: @files = params[:theme_upload][:upload].local_path .. it will return the temp directory path, not the true path. Any help would be appreciated as well as any advice going forward on this topic. Thanks. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
pharrington
2010-Jan-14 04:53 UTC
Re: Need some help understanding file_field and local_path
On Jan 13, 11:22 pm, Alpha Blue <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 7. Now I want to call an after_save method that will dir glob the > location that the (original) blue_lagoon.yml file was uploaded from, and > begin to mass create and upload the information to the public/themes > folder. > > The problem is I don''t know how to find the local_path to the current > upload because rails moved it to the temp folder.I''m confused. Rails saves the file in a temporary folder as soon as the upload''s finished. (Also, under certain situations (which I honestly don''t know off the top of my head) it might not bother with the temporary file and store the uploaded data in a StringIO object.) The file doesn''t exist on the server until the web server finishes processing the post request, and Rails or Rack or whatever saves the information where it wants. There is no "original" file. Please correct me if I''m wrong, but it sounds like you want the path of the file from the user''s machine? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Alpha Blue
2010-Jan-14 14:19 UTC
Re: Need some help understanding file_field and local_path
pharrington wrote:> I''m confused. Rails saves the file in a temporary folder as soon as > the upload''s finished. (Also, under certain situations (which I > honestly don''t know off the top of my head) it might not bother with > the temporary file and store the uploaded data in a StringIO object.) > The file doesn''t exist on the server until the web server finishes > processing the post request, and Rails or Rack or whatever saves the > information where it wants. There is no "original" file. > > Please correct me if I''m wrong, but it sounds like you want the path > of the file from the user''s machine?That''s correct. What I would like to do is mass upload everything that is globbed within that directory. Therefore I need the exact path of the file where original uploading began. Example: I click upload: I browse to a file located in say C:\myfolder\mytheme\mytheme.yml The structure of that folder is: C:\myfolder\mytheme\images\* C:\myfolder\mytheme\layouts\* C:\myfolder\mytheme\javascripts\* C:\myfolder\mytheme\stylesheets\* C:\myfolder\mytheme\swfs\* C:\myfolder\mytheme\mytheme.yml The first step was to read the mytheme.yml file as a manifest for what will be usable/uploaded for the theme. In some cases, certain themes might not include swfs, javascripts, or even layouts. The yml is read and placed into the database model as a record manifest for the theme. After the yml manifest is saved, I want to go back to the original folder where the browse/upload began and then glob the structure to make sure it matches the manifest and then I''ll create directories in the public\themes folder of the application and copy the file structure from that root location exactly. How can I accomplish this? From other real-web examples, I see multiple file uploads but they all have javascript attached to them that provide multiple file_field inputs. I''m looking to mass glob upload files based off a directory location. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Jan-14 14:52 UTC
Re: Need some help understanding file_field and local_path
On Jan 14, 2:19 pm, Alpha Blue <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> pharrington wrote:> How can I accomplish this? From other real-web examples, I see multiple > file uploads but they all have javascript attached to them that provide > multiple file_field inputs. I''m looking to mass glob upload files based > off a directory location.You can''t (at least not with plain html + javascript) - you don''t have access to the user''s filesystem. I think that HTML5 adds some stuff in this area (not sure what changes are and what has actually been implemented) Fred> -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Alpha Blue
2010-Jan-14 15:20 UTC
Re: Need some help understanding file_field and local_path
Frederick Cheung wrote:> On Jan 14, 2:19 pm, Alpha Blue <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> pharrington wrote: > >> How can I accomplish this? From other real-web examples, I see multiple >> file uploads but they all have javascript attached to them that provide >> multiple file_field inputs. I''m looking to mass glob upload files based >> off a directory location. > > You can''t (at least not with plain html + javascript) - you don''t have > access to the user''s filesystem. I think that HTML5 adds some stuff in > this area (not sure what changes are and what has actually been > implemented) > > FredThanks Fred, that''s what I thought. Well that''s not a big issue then. In most cases if someone wanted to add a completely new theme to their site, they would have to upload the files themselves anyways. As long as I''m able to see the yml manifest and understand what''s in the theme and how it''s being used, I should be okay. Thanks for the clarification. However, if someone has the time, I''d still like to know how I can find the user directory that someone was attempting to load from. I''d like to know this for future reference. Take care. -- Posted via http://www.ruby-forum.com/. --002354530770b428c0047d216ee2 Content-Type: text/plain; charset=ISO-8859-1 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. --002354530770b428c0047d216ee2--
Matt Jones
2010-Jan-15 14:03 UTC
Re: Need some help understanding file_field and local_path
On Jan 14, 10:20 am, Alpha Blue <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Thanks for the clarification. > > However, if someone has the time, I''d still like to know how I can find > the user directory that someone was attempting to load from. I''d like > to know this for future reference. >I don''t believe that most browsers send that info - as a matter of fact, I believe that IE''s sending of a full path (rather than the plain filename) is regarded as a bug, rather than a feature. See, for example, this ticket: http://issues.apache.org/jira/browse/FILEUPLOAD-122 (from Jboss, but I remember seeing a comment about this in paperclip/ attachment_fu/etc. as well) --Matt Jones -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Jan-15 14:35 UTC
Re: Need some help understanding file_field and local_path
Alpha Blue wrote: [...]> However, if someone has the time, I''d still like to know how I can find > the user directory that someone was attempting to load from. I''d like > to know this for future reference.There is no reason that you or your app should have any interest in the particulars of your client''s filesystem. It is, quite frankly, none of your app''s business, just as your server''s filesystem is none of the client''s business.> > Take care.Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. --0022158df84ffff855047d34ebb8 Content-Type: text/plain; charset=ISO-8859-1 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. --0022158df84ffff855047d34ebb8--
Curtis Schofield
2010-Jan-15 14:51 UTC
Re: Re: Need some help understanding file_field and local_path
On Fri, Jan 15, 2010 at 6:35 AM, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> Alpha Blue wrote: > [...] > > However, if someone has the time, I''d still like to know how I can find > > the user directory that someone was attempting to load from. I''d like > > to know this for future reference. > > There is no reason that you or your app should have any interest in the > particulars of your client''s filesystem. It is, quite frankly, none of > your app''s business, just as your server''s filesystem is none of the > client''s business. > >Marnen is correct here. Please understand that while I understand that you may be interested in doing more work so the user does less - it is wiser to not get to interested about the users filesystem and I would encourage you to only accept ZIP files in this case and spend the time validating the directory structure and any requried files and assist the user via docs and or some step by step wizard ( for newbs ) to make your theme file. I expect anyone that can make said theme is actually very competent. Know your audience. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Alpha Blue
2010-Jan-15 15:32 UTC
Re: Re: Need some help understanding file_field and local_path
I don''t need to implement the upload feature for bulk files any longer. All I use now is an upload to the yml configuration file for the theme. My question was asked more out of curiosity. Rails needed to know the original path to move the file to the temporary path. I was only curious what method(s) Rails used to perform that scenario. But, again, I only asked out of curiosity. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Jan-15 17:19 UTC
Re: Need some help understanding file_field and local_path
On Jan 15, 3:32 pm, Alpha Blue <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I don''t need to implement the upload feature for bulk files any longer. > All I use now is an upload to the yml configuration file for the theme. > My question was asked more out of curiosity. Rails needed to know the > original path to move the file to the temporary path. I was only > curious what method(s) Rails used to perform that scenario. >It doesn''t - the webserver gets a stream of bytes from the client (with some metadata) and plonks those bytes somewhere temporary (or not at all for small uploads). Fred> But, again, I only asked out of curiosity. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Adam Stegman
2010-Jan-15 22:40 UTC
Re: Need some help understanding file_field and local_path
Not to mention, your code is on the server. You can''t access the client''s file system from the server anyway. Dir.glob would fail because you''d be globbing your own disk. On Jan 15, 8:35 am, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Alpha Blue wrote: > > [...] > > > However, if someone has the time, I''d still like to know how I can find > > the user directory that someone was attempting to load from. I''d like > > to know this for future reference. > > There is no reason that you or your app should have any interest in the > particulars of your client''s filesystem. It is, quite frankly, none of > your app''s business, just as your server''s filesystem is none of the > client''s business. > > > > > Take care. > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Alpha Blue
2010-Jan-15 22:48 UTC
Re: Need some help understanding file_field and local_path
Frederick Cheung wrote:> It doesn''t - the webserver gets a stream of bytes from the client > (with some metadata) and plonks those bytes somewhere temporary (or > not at all for small uploads). > > FredThanks Fred, that satisfies my curiosity. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.