File Attachment

I have recently been looking for examples where it was possible to
attach files along with a form submission, but I have found little about
it. In the near future I plan to implement this functionality in my RoR
web application and was wondering if there was any info or examples that
can be provided.

-Gilles

Agile Web D. with Rails - 2nd Ed has a section on attaching
images. That may help you.

Regards,
Dave Dumaresq


Information and Educational Technology
Kwantlen University College - 604-599-2120
“So powerful is the light of unity that it can illuminate the whole
earth.” --Bahá'u’lláh

Gilles [email protected]
Sent by: [email protected]
08/21/2006 09:46 AM
Please respond to
[email protected]

To
[email protected]
cc

Subject
[Rails] File Attachment

I have recently been looking for examples where it was possible to
attach files along with a form submission, but I have found little about
it. In the near future I plan to implement this functionality in my RoR
web application and was wondering if there was any info or examples that
can be provided.

-Gilles


Posted via http://www.ruby-forum.com/.

scenarios which seem to be used a lot :

file_column plugin

acts_as_attachment plugin

Gilles wrote:

I have recently been looking for examples where it was possible to
attach files along with a form submission, but I have found little about
it. In the near future I plan to implement this functionality in my RoR
web application and was wondering if there was any info or examples that
can be provided.

-Gilles

Actually, this link: Peak Obsession
might be quicker for you and it’s free.

Hello Gilles,

For a second reference with working examples (ones I use myself) check
out these posts–

First the basic form setup and Ruby needed to move files:
http://www.forthecode.com/user/index/15

Second a File Uploading Model to help move files on your filesystem and
save data about those files to your database:
http://www.forthecode.com/user/index/21

This code definitely needs a bit of refactoring, but it regardless - it
does work.

Regards,

Charles

Gilles wrote:

I have recently been looking for examples where it was possible to
attach files along with a form submission, but I have found little about
it. In the near future I plan to implement this functionality in my RoR
web application and was wondering if there was any info or examples that
can be provided.

-Gilles

Ahh, thanks for the links. So I have a text field that gets filled in
with the file path after choosing a file by browsing the local hard
drive. I realize that when submitted, the file goes to my windows/temp
directory as a windows user. I haven’t done anything similar before.
It’s saving it in the form CGIxxxx.x, where the x’s are numbers, much
like in the forthecode walkthrough which I am following.

There are problems with moving the file out of the temp directory to an
appropriate directory in my web application. When using the FileUtils.mv
function I get a permission denied rails error in my browser. That file
is being used by something, so I copied the file instead. I don’t know
if there will be a problem with uploaded temp files overcrowding the
temp folder. On a similar note, is there an optimal place to put
uploaded files within my RoR directory structure?

Also, what about security issues. How do I prevent malicious files from
entering my uploads directory with the potential to cause havoc or files
that are extremely big taking up space, etc.?

Eventually, when all this is sorted out, how would I go about providing
a link to the upload associated with the form I am viewing, so I can
download it or view it in my browser?

I apologize for all the questions. I am unsure about many aspects of
uploading files and was unable to find much information regarding it in
ruby on rails.

-Gilles