如何将从S3收到的文件作为二进制响应发送到Gin?
比方说,我有以下代码从S3 bucket获取图像:
response, err := i.s3Client.GetObject(context.TODO(), &s3.GetObjectInput{
Bucket: aws.String("test"),
Key: aws.String(filename),
})
如何将此响应导入Gin路由的响应上下文?
我可以这样做:
body, err := ioutil.ReadAll(response.Body)
if err != nil {
ctx.JSON(http.StatusBadRequest, err)
return
}
但如何让杜松子wine 作为输出?我脑海中浮现的但行不通的是:
ctx.Header("Content-Type", *response.ContentType)
ctx.Header("Cache-control", "max-age="+strconv.Itoa(60*60*24*365))
ctx.Write(body)
我能在这里做点什么吗?