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

后端 未结 2 1721
春和景丽
春和景丽 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:25

    Using the aws-sdk gem, you can get a temporary signed url for any S3 object by calling url_for:

    s3 = AWS::S3.new(
      :access_key_id => 1234,
      :secret_access_key => abcd
    )
    object = s3.buckets['bucket'].objects['path/to/object']
    object.url_for(:get, { :expires => 20.minutes.from_now, :secure => true }).to_s
    

    This will give you a signed, temporary use URL for only that object in S3. It expires after 20 minutes (in this example), and it's only good for that one object.

    If you have lots of objects the client needs, you'll need to issue lots of signed URLs.

    Or should let the server control all content passing (this solves security of course)? Does this mean I have to download all content to server before handing it down to the connected users?

    Note that this doesn't mean the server needs to download each object, it only needs to authenticate and authorize specific clients to access specific objects in S3.

    API docs from Amazon: https://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html#RESTAuthenticationQueryStringAuth

提交回复
热议问题