doudiyu1639 2015-12-26 07:12
浏览 35
已采纳

安全地从S3提供内容

I'm writing a web application in go and I'm using amazon s3 to store all the user files, this include the profile pics and text and audio files.

However I'm struggling to understand what will be the correct way to do this securely. What I was thinking is after making sure the request comes from an authenticated user with access to the requested file, just use the aws go library to fetch the file and write it to the http request.

Something like this:

import (
    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/s3"
    "io"
)

func serveFile(file string, w http.ResponseWriter) {
    svc := s3.New(session.New(), aws.NewConfig().WithRegion(config.AWS.Region))

    params := &s3.GetObjectInput{
    Bucket: aws.String("Bucket name"),
    Key:    aws.String(file),
    }

    resp, err := svc.GetObject(params)
    n, err := io.Copy(w, resp.Body)

}

I don't have much experience working with AWS so I'm not sure this is even a good approach, but it works. Is this a good way to do it, for a production server? Is there a better, more reliable way?

  • 写回答

2条回答 默认 最新

  • dtn36013 2015-12-26 08:17
    关注

    This method can work. But it relies on requests being proxied through your client.

    The recommend way is to use signed urls. This creates a url that is valid for a time period that you specify that allows the end user to download a file directly from S3.

    Your key is not exposed as the url contains just a signature.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改