當前位置: 首頁>>代碼示例>>Golang>>正文


Golang PutObjectInput.Bucket方法代碼示例

本文整理匯總了Golang中github.com/aws/aws-sdk-go/service/s3.PutObjectInput.Bucket方法的典型用法代碼示例。如果您正苦於以下問題:Golang PutObjectInput.Bucket方法的具體用法?Golang PutObjectInput.Bucket怎麽用?Golang PutObjectInput.Bucket使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/aws/aws-sdk-go/service/s3.PutObjectInput的用法示例。


在下文中一共展示了PutObjectInput.Bucket方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestS3Connection

func (s *S3Suite) TestS3Connection(c *C) {
	createBucket := s3.CreateBucketInput{Bucket: aws.String("bucket")}
	_, err := s.svc.CreateBucket(&createBucket)
	c.Assert(err, IsNil)

	conn := NewS3Connection(credentials.AnonymousCredentials, "bucket", "prefix", s.region, s.endpoint)
	files, err := conn.ListDir("path", nil)
	c.Assert(err, IsNil)
	c.Assert(len(files.Files), Equals, 0)

	buffer := bytes.NewReader(make([]byte, 100))
	putObject := s3.PutObjectInput{}
	putObject.Bucket = aws.String("bucket")
	putObject.Key = aws.String("prefix/banana")
	putObject.Body = buffer
	s.svc.PutObject(&putObject)

	putObject = s3.PutObjectInput{}
	putObject.Bucket = aws.String("bucket")
	putObject.Key = aws.String("prefix/sampledir/")
	putObject.Body = bytes.NewReader(make([]byte, 0))
	s.svc.PutObject(&putObject)

	putObject = s3.PutObjectInput{}
	putObject.Bucket = aws.String("bucket")
	putObject.Key = aws.String("prefix/sampledir/a")
	putObject.Body = bytes.NewReader(make([]byte, 0))
	s.svc.PutObject(&putObject)

	putObject = s3.PutObjectInput{}
	putObject.Bucket = aws.String("bucket")
	putObject.Key = aws.String("prefix/sampledir/b")
	putObject.Body = bytes.NewReader(make([]byte, 0))
	s.svc.PutObject(&putObject)

	files, err = conn.ListDir("", nil)
	fmt.Printf("files=%s\n", files)
	c.Assert(err, IsNil)
	c.Assert(len(files.Files), Equals, 2)
	f := files.Files[1]
	c.Assert(f.Name, Equals, "banana")
	c.Assert(f.Size, Equals, uint64(100))
	c.Assert(f.IsDir, Equals, false)

	f = files.Files[0]
	c.Assert(f.Name, Equals, "sampledir")
	c.Assert(f.Size, Equals, uint64(0))
	c.Assert(f.IsDir, Equals, true)
}
開發者ID:pgm,項目名稱:singleply,代碼行數:49,代碼來源:s3_test.go

示例2: TestS3ModifyDuringRead

func (s *S3Suite) TestS3ModifyDuringRead(c *C) {
	createBucket := s3.CreateBucketInput{Bucket: aws.String("modified")}
	_, err := s.svc.CreateBucket(&createBucket)
	c.Assert(err, IsNil)

	// upload a file
	buffer := bytes.NewReader(make([]byte, 100))
	putObject := s3.PutObjectInput{}
	putObject.Bucket = aws.String("modified")
	putObject.Key = aws.String("prefix/banana")
	putObject.Body = buffer
	s.svc.PutObject(&putObject)

	// make sure ListDir sees it
	conn := NewS3Connection(credentials.AnonymousCredentials, "modified", "prefix", s.region, s.endpoint)
	files, err := conn.ListDir("", nil)
	c.Assert(err, IsNil)
	c.Assert(len(files.Files), Equals, 1)
	f := files.Files[0]
	c.Assert(f.Name, Equals, "banana")

	localFile, _ := ioutil.TempFile(c.MkDir(), "local")
	localPath := localFile.Name()
	localFile.Close()

	status := &NullStatusCallback{}

	// Perform a read
	region, err := conn.PrepareForRead("banana", f.Etag, localPath, 0, 10, status)
	c.Assert(err, IsNil)
	c.Assert(region.Offset, Equals, uint64(0))
	c.Assert(region.Length, Equals, uint64(10))

	// upload new version of object
	buffer = bytes.NewReader(make([]byte, 101))
	putObject = s3.PutObjectInput{}
	putObject.Bucket = aws.String("modified")
	putObject.Key = aws.String("prefix/banana")
	putObject.Body = buffer
	s.svc.PutObject(&putObject)

	// try a read, and we should get a failure because data changed, and hence Etag
	_, err = conn.PrepareForRead("banana", f.Etag, localPath, 10, 20, status)
	c.Assert(err, Equals, UpdateDetected)
}
開發者ID:pgm,項目名稱:singleply,代碼行數:45,代碼來源:s3_test.go


注:本文中的github.com/aws/aws-sdk-go/service/s3.PutObjectInput.Bucket方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。