Tim wrote:
> I am wanting to add the ability for a user to upload a set of files and
> then have the server do some post processing of those files. Since there
> may be several files in an uploaded set I think it would be best to just
> allow the user to specify a client-side directory and then have that dir
> zipped and uploaded and then have the server unzip and process the
> contained files... Being *extremely* new to rails and web development,
> though, I have some (probably very simple) questions.
>
> 1. Is javascript my only option client-side for zipping the files the
> user wants to send? If so I could just instruct the users to zip the
> files themselves and the upload the zip file...
JavaScript wouldn''t be able to do this - web applications
don''t have
free access to a user''s files.
> 2. I am familiar with web services (I used to do .NET and utilized them
> in a few distributed desktop apps) and am thinking that the post
> processors might be good cadidates for being implemented as such. These
> would most likely not be consumed outside of this rails app, though -
> would implementing them as web services be overkill?
I suggest you keep things as simple as possible. Can the post-processing
be done asynchronously, or does it have to be completed before the user
sees a response? If it can be done asynchronously, one approach would be
for the web application to drop the zipped files in a "pending"
directory and have a separate process polling that directory and doing
the unzipping and post-processing.
It''s a good idea to make the turnaround of web requests/responses as
quick as possible, so if you can make the post-processing asynchronous
that would help.
> 3. Being so new to web development, I''m not sure I understand how
the
> file upload semantics in rails work. How does the server know what has
> been uploaded and where it is? Once it is uploaded, are there any
> restrictions on what the server can do with it? I am thinking that rails
> would only have rights to access files under the app root and maybe /tmp
> ... is that right?
In any web application handling file upload, the file content, content
type and original name are embedded in the body of the HTTP request.
Rails gives you access to this data. Your application has to decide what
to do with it - you could write a file on the server, or you could put
the data in a database.
How much flexibility you have in where you can write files and what you
can do with them afterwards may depend on your hosting arrangements, but
in general Rails processes will be running as some user or other (a
defined user on the host, nothing to do with the user who is doing the
uploading), and will be able to write files wherever that user has
permission to write files. Once they have been written, there''s nothing
special about them - you can do whatever you want with them.
If users'' files are private, be sure not to upload them to a browsable
directory.
> 4. I have checked out the upload progress demo but am still a little
> foggy... Do I need to run rails from cvs if I want to utilize the cool
> upload progress stuff?
In
http://weblog.rubyonrails.com/archives/2005/07/06/rails-0-13-225-features-fixes-in-75-days
DHH wrote: "We also have Ajaxified progress indicators for file uploads
in as an experimental feature in this release. It makes for a much more
user-friendly experience uploading large files. See the demo. It’s
experimental nature means that it only works on Apache, lighttpd 1.4.x,
and only in some environments. Consider it a preview of really cool
tech. You need to include ActionController::Base.enable_upload_progress
in your environment.rb file to turn it on."
So it''s there in the current Rails, but whether or not you can use it
depends on your environment.
> Thanks for bearing with my beginner questions and, of course, for any
> help anyone can throw my way. :-)
Hope that helps.
Justin