dongyan7876 2016-10-26 18:43
浏览 60
已采纳

使用Golang SDK的S3对象不会过期

Using the AWS Golang SDK, I'm attempting to set an expiration date for some of the objects that I'm uploading. I'm pretty sure that the header is being set correctly, however, when logging into S3 and viewing the properties of the new object, it doesn't appear to have a expiration date.

Below is a snippet of how I'm uploading objects

exp := time.Now()
exp = exp.Add(time.Hour * 24)

svc := s3.New(session.New(config))
_, err = svc.PutObject(&s3.PutObjectInput{
    Bucket:        aws.String("MyBucketName"),
    Key:           aws.String("201700689.zip"),
    Body:          fileBytes,
    ContentLength: aws.Int64(size),
    ContentType:   aws.String(fileType),
    Expires:       &exp,
})

And here is what I see when logging into the site enter image description here

Any idea what is going on here? Thanks

  • 写回答

1条回答 默认 最新

  • douqianxun8540 2016-10-26 23:27
    关注

    Well, Expires is just the wrong field:

    // The date and time at which the object is no longer cacheable.

    What you want is Object Expiration which can be set as a bucket rule and not per object.

    Basically, you add a Lifecycle rule (on the bucket properties) specifying:

    Each rule has the following attributes:

    Prefix – Initial part of the key name, (e.g. logs/), or the entire key name. Any object in the bucket with a matching prefix will be subject to this expiration rule. An empty prefix will match all objects in the bucket.

    Status – Either Enabled or Disabled. You can choose to enable rules from time to time to perform deletion or garbage collection on your buckets, and leave the rules disabled at other times.

    Expiration – Specifies an expiration period for the objects that are subject to the rule, as a number of days from the object’s creation date.

    Id – Optional, gives a name to the rule.

    This rule will then be evaluated daily and any expired objects will be removed.

    See https://aws.amazon.com/blogs/aws/amazon-s3-object-expiration/ for a more in-depth explanation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题