How to store data in S3 and allow user access in a secure way with rails API / iOS client?

后端 未结 2 1722
春和景丽
春和景丽 2020-11-30 17:01

I am new to writing Rails and APIs. I need some help with S3 storage solution. Here\'s my problem.

I am writing an API for an iOS app where the users login with the

2条回答
  •  时光取名叫无心
    2020-11-30 17:23

    The above answers use the old aws-sdk-v1 gem rather than the new aws-sdk-resources version 2.

    The new way is:

    aws_resource = Aws::S3::Resource::new
    aws_resource.bucket('your_bucket').object('your_object_key').presigned_url(:get, expires_in: 1*20.minutes)
    

    where your_object_key is the path to your file. If you need to look that up, you would use something like:

    s3 = Aws::S3::Client::new
    keys = []
    s3.list_objects(bucket: 'your_bucket', prefix: 'your_path').contents.each { |e| 
      keys << e.key
    }
    

    That information was startlingly difficult to dig up, and I almost just gave up and used the older gem.

    Reference

    http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Object.html#presigned_url-instance_method

提交回复
热议问题