简体   繁体   English

如何将大文件上传到rails应用程序?

[英]How to upload big files to a rails application?

I have a ruby application that's used by users via a rails web app. 我有一个ruby应用程序,用户通过rails web应用程序使用。

The use case that i need to solve is: each user needs to compile create an entity on database via the web page and put a really big attachment (can be 100gigs or more too) related to the entity. 我需要解决的用例是:每个用户需要通过网页编译在数据库上创建实体,并放置一个与实体相关的非常大的附件(也可以是100gig或更多)。

Now this is too big to be handled by normal upload plugins, i am searching for a way to solve this problem, my ideas are: - delegate the upload via http to backgroundrb - develop a GTK gui and ship it to user to do the upload 现在这太大了,无法通过普通上传插件处理,我正在寻找解决这个问题的方法,我的想法是: - 通过http委托上传到backgroundrb - 开发GTK gui并将其发送给用户进行上传

any other hint or ideas? 任何其他提示或想法?

thanks 谢谢

If it's >100GB, you should probably be using an upload manager of some kind. 如果它> 100GB,你可能应该使用某种上传管理器。 If your network speed is fast enough, you could just build a trusted applet to communicate with the server. 如果您的网络速度足够快,您可以构建一个受信任的applet来与服务器通信。 The trusted applet would have full file permission, so it would work just like a standalone application. 受信任的applet具有完整的文件权限,因此它就像独立的应用程序一样工作。 In this manner, you could avoid needing to distribute a separate utility for file transfer. 通过这种方式,您可以避免需要为文件传输分发单独的实用程序。

Alternatively, you could generate some token on the web, and then let users use a standalone application with the given token to upload their file. 或者,您可以在Web上生成一些令牌,然后让用户使用带有给定令牌的独立应用程序上载其文件。

Transferring 100GB over a web interface makes me cringe. 通过网络界面传输100GB让我感到畏缩。 It would be much better to write/use a standalone application to do the transfer. 编写/使用独立应用程序进行传输会好得多。

If you are already using Ruby, you can write a Ruby-based app that uploads over FTP. 如果您已经在使用Ruby,那么您可以编写一个基于Ruby的应用程序,通过FTP上传。 For example: 例如:

require 'net/ftp'

Net::FTP.open('uploads.yoursite.com','username','password') {|ftp|
    ftp.login('username','password')
    ftp.put 'filename'
    if (ftp.last_response != "266 Transfer complete.\n")
        puts "Error with FTP upload\nResponse was: #{ftp.last_response}"
    end
}

I use this code to upload auto-generated data files to another server that archives them. 我使用此代码将自动生成的数据文件上载到另一个存档它们的服务器。 There are several different libraries for building simple user interfaces in Ruby, and all you would need is a simple window where the user can enter their username and password, select the file to upload, and click the "Go" button. 在Ruby中有几个不同的库用于构建简单的用户界面,您只需要一个简单的窗口,用户可以输入用户名和密码,选择要上载的文件,然后单击“开始”按钮。

The Ruby SSH libraries make it possible to do a secure file transfer over SFTP (hint: require 'net/sftp' ). Ruby SSH库可以通过SFTP进行安全的文件传输(提示: require 'net/sftp' )。 I haven't used it myself, but the docs make it look as easy as FTP. 我自己没有使用它,但文档使它看起来像FTP一样简单。 IIRC, SFTP has native support for resuming interrupted transfers. IIRC,SFTP原本支持恢复中断的转移。

You could also use a utility like WinSCP , which is an open-source tool that can upload using FTP, SFTP, or SCP. 您还可以使用WinSCP这样的实用程序,它是一个可以使用FTP,SFTP或SCP上传的开源工具。 For non-Windows systems, there's Cyberduck for OS X and Kasablanka or gFTP for Linux. 对于非Windows系统,有适用于OS X和KasablankaCyber​​duck适用于Linux的gFTP

These guys have some good info on uploading large files. 这些人有一些关于上传大文件的好信息。 Maybe this will help: http://tinyw.in/67ZF 也许这会有所帮助: http//tinyw.in/67ZF

They kinda go through their process of solving their problem and the steps they took along the way. 他们有点经历他们解决问题的过程以及他们沿途采取的步骤。 Worth a peek. 值得一看。

Uploading a 100GB file through your webapp will not be very good. 通过您的webapp上传100GB文件不是很好。 That upload is going to occupy your web server for the time it takes to upload the file making it inaccessible to others. 该上传将占用您的Web服务器上传文件所需的时间,使其他人无法访问。

I'd consider using FTP or perhaps even having your users upload directly to S3 instead and then manage the files from there since I assume that you have to store these files somewhere anyways. 我考虑使用FTP或者甚至让你的用户直接上传到S3 ,然后从那里管理文件,因为我认为你必须将这些文件存储在某个地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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