gpt4 book ai didi

ruby-on-rails - 如何使用rails上传和下载图片和视频到s3 glacier

转载 作者:太空宇宙 更新时间:2023-11-03 16:13:17 25 4
gpt4 key购买 nike

我想使用 ruby​​ on rails 在 s3 冰川上上传图像和视频。现在我在 S3 冰川上创建了一个保险库并设置了所有权限。

现在我使用 rails 方法在 vault 中创建了一个存档,例如:

vault.archives.create(:body => File.open(video_path).to_s, :description => 'my first archive')

然后我创建基于存档的作业,例如:

vault.jobs.create(:type => Fog::AWS::Glacier::Job::ARCHIVE, :archive_id =>"my archive id" )

并通过以下方式获得这些工作:

vault.jobs.get("my job id")

** 它为我提供了如下响应:**

id="return my job id",
action="ArchiveRetrieval",
archive_id="return my archive id",
archive_size=24,
completed=true,
completed_at=2019-03-05 19:49:36 UTC,
created_at=2019-03-05 15:55:29 UTC,
inventory_size=0,
description=nil,
tree_hash="xxxxxx",
sns_topic=nil,
status_code="Succeeded",
status_message="Succeeded",
vault_arn="xxxxxxxxxx:vaults/myvalutname",
format=nil,
type=nil

我的问题是:

  1. Is the approach of uploading image/video in the above code is correct or not? If it's not correct please suggest me the right way for uploading.
  2. How I'll get uploaded image/video URL from the glacier s3.
  3. Where I'll see uploaded videos and images stored on the glacier. Now it only shows Number of archives in my vault.

我需要专家对我的问题提出建议。请帮帮我。

最佳答案

S3 和 Glacier 之间存在主要区别。 Glacier 的基本概念是存储用于备份的长期文件。 S3 访问速度快。但是Glacier是保存文件久了很少访问。因此,在您想要保存文件但很少检索除非出现紧急情况的地方进行备份对用户来说是有好处的。所以检索文件的代价比保存文件的代价更高。我不确定您为什么要在 Glacier 中保存视频,但要确定 Glacier 的检索速度很慢,并且要保存图像/视频,您可能会考虑使用 S3 而不是冰川。以下是对您的回答的回复

  1. 是的,你做得对,这就是你必须做的。

  2. 这有点棘手。您必须使用数据库来保存所有检索到的 ID。所以以后你可以很容易地检索。这意味着您可以将所有信息保存在数据库中,而不是拥有任何目录,以便稍后您可以检索它。

id="return my job id",   # save it to database
action="ArchiveRetrieval",
archive_id="return my archive id", # better save in relation table of archives
archive_size=24,
completed=true,
completed_at=2019-03-05 19:49:36 UTC,
created_at=2019-03-05 15:55:29 UTC,
inventory_size=0,
description=nil,
tree_hash="xxxxxx",
sns_topic=nil,
status_code="Succeeded",
status_message="Succeeded",
vault_arn="xxxxxxxxxx:vaults/myvalutname",
format=nil,
type=nil

所以这意味着您将在数据库中拥有以下字段以访问所有上传内容。

  1. 要检索文件,您必须使用数据库并获取所有内容。现在只需使用您的对象 ID 即可获取您的文件。
archive_id         -          id             -  description
return my archive id - return my job id - my first archive

当你想做一个文件列表时,只需运行 ActiveRecord 数据库记录来获取它并以某种方式链接它,以便操作可以使用对象 ID 检索该文件。

关于ruby-on-rails - 如何使用rails上传和下载图片和视频到s3 glacier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55019065/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com