使用Go SDK(Amazon S3)从存储桶生成种子文件

huangapple go评论101阅读模式
英文:

Generate Torrent from Bucket via Go SDK (Amazon S3)

问题

我正在尝试找出一种使用AWS SDK for Go从存储桶生成种子文件的方法。

我正在使用预签名URL(因为这是一个私有存储桶):

svc := s3.New(session.New(config))
req, _ := svc.GetObjectRequest(&s3.GetObjectInput{
    Bucket: aws.String("bucketName"),
    Key:    "key",
})
// 签署URL
url, err := req.Presign(120 * time.Minute)

根据文档,要生成种子文件,语法如下:

GET /ObjectName?torrent HTTP/1.1
Host: BucketName.s3.amazonaws.com
Date: date
Authorization: authorization string

在Go中,如何将 ?torrent 参数添加到预签名URL中?

英文:

I'm trying to figure out a way to generate torrent files from a bucket, using the AWS SDK for Go.

I'm using a pre-signed url (since its a private bucket):

svc := s3.New(session.New(config))
	req, _ := svc.GetObjectRequest(&s3.GetObjectInput{
		Bucket: aws.String("bucketName"),
		Key:    "key",
	})
    // sign the url
	url, err := req.Presign(120 * time.Minute)

From the docs, to generate a torrent, the syntax:

GET /ObjectName?torrent HTTP/1.1
Host: BucketName.s3.amazonaws.com
Date: date
Authorization: authorization string

How do I add the ?torrent parameter to a presigned url in GO?

答案1

得分: 1

尝试使用AWS Go SDK中的GetOBjectTorrent方法。它会在响应中返回一个.torrent文件,以下是示例代码:

svc := s3.New(session.New())
input := &s3.GetObjectTorrentInput{
    Bucket: aws.String("bucketName"),
    Key:    aws.String("key"),
}

result, _ := svc.GetObjectTorrent(input)
fmt.Println(result)

请参阅http://docs.aws.amazon.com/sdk-for-go/api/service/s3/#S3.GetObjectTorrent了解更多详细信息。希望能对你有所帮助。

英文:

Try GetOBjectTorrent method on the AWS Go SDK. It will return you .torrent file in response, here is example code:

svc := s3.New(session.New())
input := &s3.GetObjectTorrentInput{
    Bucket: aws.String("bucketName"),
    Key:    aws.String("key"),
}

result, _ := svc.GetObjectTorrent(input)
fmt.Println(result)

Please see http://docs.aws.amazon.com/sdk-for-go/api/service/s3/#S3.GetObjectTorrent for more details. Hope it helps.

huangapple
  • 本文由 发表于 2017年8月21日 01:37:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/45785038.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定