本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/s3.PutObjectInput类的典型用法代码示例。如果您正苦于以下问题:Golang PutObjectInput类的具体用法?Golang PutObjectInput怎么用?Golang PutObjectInput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PutObjectInput类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: writeToS3
// writeToS3 uploads the given file to S3
func writeToS3(s3Conn s3Connection, input io.ReadSeeker, disableEncryption bool) error {
params := s3.PutObjectInput{
Bucket: aws.String(s3Conn.bucket),
Key: aws.String(s3Conn.key),
Body: input,
}
if !disableEncryption {
algo := aesAlgo
params.ServerSideEncryption = &algo
}
_, err := s3Conn.handler.PutObject(¶ms)
return err
}
开发者ID:Clever,项目名称:mongo-op-throttler,代码行数:14,代码来源:pathio.go
示例2: PutObjectRequest
// PutObjectRequest creates a temp file to encrypt the contents into. It then streams
// that data to S3.
//
// Example:
// svc := s3crypto.New(session.New(), s3crypto.AESGCMContentCipherBuilder(handler))
// req, out := svc.PutObjectRequest(&s3.PutObjectInput {
// Key: aws.String("testKey"),
// Bucket: aws.String("testBucket"),
// Body: bytes.NewBuffer("test data"),
// })
// err := req.Send()
func (c *EncryptionClient) PutObjectRequest(input *s3.PutObjectInput) (*request.Request, *s3.PutObjectOutput) {
req, out := c.S3Client.PutObjectRequest(input)
// Get Size of file
n, err := input.Body.Seek(0, 2)
if err != nil {
req.Error = err
return req, out
}
input.Body.Seek(0, 0)
dst, err := getWriterStore(req, c.TempFolderPath, n >= c.MinFileSize)
if err != nil {
req.Error = err
return req, out
}
encryptor, err := c.ContentCipherBuilder.ContentCipher()
req.Handlers.Build.PushFront(func(r *request.Request) {
if err != nil {
r.Error = err
return
}
md5 := newMD5Reader(input.Body)
sha := newSHA256Writer(dst)
reader, err := encryptor.EncryptContents(md5)
if err != nil {
r.Error = err
return
}
_, err = io.Copy(sha, reader)
if err != nil {
r.Error = err
return
}
data := encryptor.GetCipherData()
env, err := encodeMeta(md5, data)
if err != nil {
r.Error = err
return
}
shaHex := hex.EncodeToString(sha.GetValue())
req.HTTPRequest.Header.Set("X-Amz-Content-Sha256", shaHex)
dst.Seek(0, 0)
input.Body = dst
err = c.SaveStrategy.Save(env, r)
r.Error = err
})
return req, out
}
开发者ID:acquia,项目名称:fifo2kinesis,代码行数:68,代码来源:encryption_client.go
示例3: Save
// Save will save the envelope contents to s3.
func (strat S3SaveStrategy) Save(env Envelope, req *request.Request) error {
input := req.Params.(*s3.PutObjectInput)
b, err := json.Marshal(env)
if err != nil {
return err
}
instInput := s3.PutObjectInput{
Bucket: input.Bucket,
Body: bytes.NewReader(b),
}
if strat.InstructionFileSuffix == "" {
instInput.Key = aws.String(*input.Key + DefaultInstructionKeySuffix)
} else {
instInput.Key = aws.String(*input.Key + strat.InstructionFileSuffix)
}
_, err = strat.Client.PutObject(&instInput)
return err
}
开发者ID:acquia,项目名称:fifo2kinesis,代码行数:22,代码来源:strategy.go
示例4: createKeys
func createKeys(t *testing.T, bucket *Bucket, keys ...keyMeta) []keyMeta {
for _, key := range keys {
req := s3.PutObjectInput{
Body: bytes.NewReader([]byte("Data")),
Bucket: aws.String(bucket.Name),
Key: aws.String(key.key),
}
if key.meta != nil {
req.Metadata = map[string]*string{}
for k, v := range key.meta {
req.Metadata[k] = &v
}
}
if _, err := bucket.Client.PutObject(&req); err != nil {
t.Fatalf("Error while creating key %s in %s: %s", key, bucket.Name, err)
}
}
return keys
}
开发者ID:abustany,项目名称:s3piegel,代码行数:23,代码来源:main_test.go
示例5: 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
示例6: 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
注:本文中的github.com/aws/aws-sdk-go/service/s3.PutObjectInput类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论