doujing5937 2018-07-18 18:13
浏览 250
已采纳

AWS S3上传的文件未显示

I am using golang sdk to upload files to a bucket on amazon S3.The response gives no error and the file is uploaded successfully. My problem is when I am listing the objects of the bucket in the same region in which I have uploaded a new .jpg file. I am getting same files list with no new file added to the Bucket. I don't know what I am doing wrong. This is the code that I am using to list objects inside the bucket.

input := &s3.ListObjectsInput{
    Bucket: aws.String("Bucket Name"),
}
result2, err := svc.ListObjects(input)
if err != nil {
    if aerr, ok := err.(awserr.Error); ok {
        switch aerr.Code() {
        case s3.ErrCodeNoSuchBucket:
            fmt.Println(s3.ErrCodeNoSuchBucket, aerr.Error())
        default:
            fmt.Println(aerr.Error())
        }
    } else {
        // Print the error, cast err to awserr.Error to get the Code and
        // Message from an error.
        fmt.Println(err.Error())
    }
    return
}
log.Println("Bucket List", result2)
  • 写回答

1条回答 默认 最新

  • dsm0688 2018-08-08 14:25
    关注

    s3 is eventually consistent and may not show an object that has been recently written in a list, even from within the same zone:

    Amazon S3 achieves high availability by replicating data across multiple servers within Amazon's data centers. If a PUT request is successful, your data is safely stored. However, information about the changes must replicate across Amazon S3, which can take some time, and so you might observe the following behaviors:

    A process writes a new object to Amazon S3 and immediately lists keys within its bucket. Until the change is fully propagated, the object might not appear in the list.

    A process replaces an existing object and immediately attempts to read it. Until the change is fully propagated, Amazon S3 might return the prior data.

    A process deletes an existing object and immediately attempts to read it. Until the deletion is fully propagated, Amazon S3 might return the deleted data.

    A process deletes an existing object and immediately lists keys within its bucket. Until the deletion is fully propagated, Amazon S3 might list the deleted object.

    see S3 developer guide

    There is a polling Go AWS API call "func (*S3) WaitUntilObjectExists" which keeps looking for a file until it appears or a time out happens

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

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料