简体   繁体   中英

How to upload and download image and video to s3 glacier using rails

I want to upload images and videos on s3 glacier using ruby on rails. Now I created a vault on S3 glacier and set all permissions.

Now I created an archive inside vault using rails method like :

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

And after that I create archive based job like:

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

And getting these jobs by:

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

** it provides me the response like:**

 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

My questions are:

  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.

I need the Experts suggestions for my problem. Please help me out.

There is a primary difference between S3 and Glacier. The basic concept of Glacier is to store long term files for backups. S3 is quick to access. But Glacier is to save files for a long time rarely access. So it is good to the user for doing backups where you want to save files but rarely retrieve unless any emergency arise. So the price to retrieve the file is more expensive than saving it. I am not sure why you want to save videos in Glacier but be firm that retrieval speed of Glacier is slow, and to save images/videos you may consider S3 than a glacier. Following is a reply to your answer

  1. Yes, you are doing correctly, and this is the way you have to do it.

  2. This is a little bit tricky. You have to use the database to save all those ids retrieved. So later you can easily retrieve. That meant instead of having any directory you can save all information in the database so later on you can retrieve it.

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

So it mean all uploads you will have following fields in db to access back.

  1. To retrieve files you have to use your database and get everything. Now just use your object ID to get your file.
archive_id         -          id             -  description
return my archive id  -   return my job id  -  my first archive

When you want to do a list of files, just run ActiveRecord db records to get it and link it in a way so that action can retrieve that files using object id.

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