4

使用 Rails,我已经按照Heroku 这篇文章允许将文件直接上传到 S3 存储桶。我实际上关注了这篇文章,因为我之前的实现不适用于分段上传(因此,大文件)。一旦我实现了这个方法,大文件上传就好了,除了非常大的文件。

我应该注意到我偏离了这篇文章,因为我使用的是awsgem 的 v1,因为我们的 Rails 版本。

这就是我的设置方式:

S3_BUCKET = AWS::S3.new.buckets[ENV['S3_BUCKET_NAME']]

def set_s3_post_url
  @s3_media_post_url = S3_BUCKET.presigned_post(key: "product_media/#{SecureRandom.uuid}-${filename}", success_action_status: '201', acl: 'public-read')
end

如前所述,这适用于大文件(~1GB),但是当我尝试上传一个文件时,比如 10GB,它会进入大部分上传状态,然后随机失败。有时 20 分钟后,有时 1 小时后。我认为可能签名的 URL 即将到期,所以我明确设置了一个长的到期时间expires: Time.now + 4.hours,但这似乎不起作用。

如果有人有任何想法,我将非常感谢您的帮助!

更新

我尝试了@bbozo 的 using 答案maxChunkSize,但不幸的是,这似乎没有做到。但是,当我在控制台中查看 XHR 请求时,失败的请求从 AWS 返回了以下 XML 响应:

<Error>
    <Code>InternalError</Code>
    <Message>We encountered an internal error. Please try again.</Message>
    <RequestId>1231BD4A29EE5291</RequestId>
    <HostId>f5muQPj2lT2Tmqi49ffqjT4ueLimYvrWUJL6WRW+F7vgm2rL1+FOD3pmsKOEYxFaSFXzLiEZjTg=</HostId>
</Error>
4

3 回答 3

1

Plan A

Did you configure chunked uploads correctly?

https://github.com/blueimp/jQuery-File-Upload/wiki/Chunked-file-uploads

Heroku article doesn't mention anything about setting up chunked uploads in the jquery plugin which handles the file uploads,

the FAQ says:

It is possible to upload files up to 4 GB with the jQuery File Upload plugin. By making use of Chunked file uploads (with chunks smaller than 4GB), the potential file size is unlimited. The restriction of 4 GB is due to some browser limitations, which might be fixed in future updates to those browsers

The documentation for chunked uploads is here, you're supposed to define a maxChunkSize property which defines the size of the chunk

$('#fileupload').fileupload({
    maxChunkSize: 10000000 // 10 MB
});

Plan B

You could put up a minimalistic node.js instance that accepts the file upload and forwards it to S3 via the AWS SDK.

You could also probably run it on a free heroku instance because it probably can be allowed to sleep 6h a day and I've got good experience with file upload services being hosted this way

于 2016-01-18T08:06:31.767 回答
0

如果您使用 heroku + s3 文件上传,我会建议使用 gem 's3_direct_upload'。使用它,您可以将文件上传到 AWS::S3,而无需连接到 heroku 服务器。它在您的服务器和 s3-bucket 之间创建直接通信。

有关更多详细信息,您可以使用链接

有了这个,如果要验证内容或对 sizeof 文件进行一些验证,您必须使用很少的 JavaScript。

于 2016-01-18T11:11:38.690 回答
-1

我在 Signiant 担任产品经理,我们专门处理非常大的文件。我也从我们的其他一些 AWS 用户那里看到了这一点。我认为这是使用 TCP / HTTP 上传非常大的文件的神器。

您可能需要考虑使用 HTTP 以外的其他方式进行上传。我管理的产品 Signiant Flight 是基于 UDP 的,可以轻松处理非常大的文件。起价为 12,000 美元/年。

还有其他可用的免费和开源 UDP 工具,例如 UDT ( http://udt.sourceforge.net ) 和 Tsunami ( http://tsunami-udp.sourceforge.net )。要使用 UDP,您需要连接 EC2 中的服务器,然后让该服务器将数据写入 S3。

Flight 是一种托管文件传输服务 - 我们为您在云中运行服务器,速度可高达 800 - 900 Mbps。

于 2016-01-15T21:53:05.687 回答