简体   繁体   中英

Uploading/Downloading files - Ruby On Rails system

I'm attempting to create a simple file hosting system using Ruby On Rails - I have a large ammount of the system setup (including the registration of new files, and stuff) however I've realised there is a bit of a problem - I'm unsure how to actually get it so that users can upload and download files. I assume I'd need some kind of file_link attribute for my file object, but how would people upload and download files to/from the server?

Also (this may be a slightly different topic) - but how would I get the file information such as file size and name (as I need them for the upload)?

Sorry for all my questions - I've don't really deal with file handling a lot so am new to the area.

Thanks In Advance,

Regards,

Joe

You should look at Paperclip gem https://github.com/thoughtbot/paperclip

It is very easy to use and allows to upload files.

Look at Paperclip. It does a lot of the heavs lifting for you: https://github.com/thoughtbot/paperclip

As they said look at paperclip. I just did a app that allows the users to upload and delete files. To get started with paperclip use http://railscasts.com/episodes/134-paperclip

To download files after uploading them with paperclip. I did the following in the controller

def download
upload = Upload.find(params[:id])
send_file upload.uploaded.path,
            :filename => upload.uploaded_file_name,
            :type => upload.uploaded_content_type,
            :disposition => 'attachment'
flash[:notice] = "Your file has been downloaded"

end

My sample file upload app should be of help https://github.com/skillachie/File-Upload-App Need to fix a few things , but the ability to upload and download files is completely functional.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM