当前位置: 首页>>代码示例>>Golang>>正文


Golang S3.PutObject方法代码示例

本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/s3.S3.PutObject方法的典型用法代码示例。如果您正苦于以下问题:Golang S3.PutObject方法的具体用法?Golang S3.PutObject怎么用?Golang S3.PutObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/aws/aws-sdk-go/service/s3.S3的用法示例。


在下文中一共展示了S3.PutObject方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: UploadFileD

func (s *S3) UploadFileD(S3 *s3.S3, key string, file *os.File, contentType, perm string) (*s3.PutObjectInput, *s3.PutObjectOutput, error) {

	md5hex, _, _, err := Md5Sum(file)
	if err != nil {
		return nil, nil, err
	}
	//s.Log.Debugf("key:%s md5=%s", key, md5hex)
	req := &s3.PutObjectInput{
		ACL:    &perm,
		Body:   file,
		Bucket: &s.Bucket,
		//ContentLength: &size,
		ContentType: &contentType,
		Key:         &key,
	}
	res, err := S3.PutObject(req)
	if err != nil {
		return req, res, err
	}
	if res == nil {
		return req, res, fmt.Errorf("res is nil pointer")
	}
	if res.ETag == nil {
		return req, res, fmt.Errorf("res.ETag is nil pointer")
	}
	if len(*res.ETag) < 2 {
		return req, res, fmt.Errorf("*res.ETag is too short. It should have 2 characters or more")
	}
	etag := (*res.ETag)[1 : len(*res.ETag)-1]
	if md5hex != etag {
		return req, res, fmt.Errorf("md5 and ETag does not match. md5:%s ETag:%s", md5hex, etag)
	}
	return req, res, err
}
开发者ID:masahide,项目名称:goansible,代码行数:34,代码来源:s3.go

示例2: recvUpload

func recvUpload(s3serv *s3.S3, c config, files chan string) {

	for {
		path, closed := <-files

		if !closed {
			break
		}

		if f, err := os.Open(path); err == nil {
			counter := &CountReader{input: f, seeker: f, co: c}
			counter.Init()
			fmt.Print("uploading:", path)
			if _, err := s3serv.PutObject(&s3.PutObjectInput{Bucket: &c.Bucket, Key: &path, Body: counter}); err == nil {
				fmt.Println("done", counter.count)

			} else {
				fmt.Println("error uploading file:", err)
			}

		} else {
			fmt.Printf("error opening file:", err)
		}
	}
}
开发者ID:sigsegvat,项目名称:syncaws,代码行数:25,代码来源:aws.go

示例3: uploadFile

func uploadFile(file string, conf config, svc *s3.S3, results chan<- result) {
	obj, err := newObjectInfo(file)
	if err != nil {
		results <- result{err: fmt.Errorf("unable to read file: %v", err)}
		return
	}

	bname := conf.Buckets[bucketName].Name
	params := &s3.PutObjectInput{
		Bucket:      &bname,
		Key:         &obj.key,
		Body:        obj.body,
		ContentType: &obj.contentType,
	}

	if !private {
		params.ACL = aws.String("public-read")
	}

	_, err = svc.PutObject(params)

	if err != nil {
		results <- result{err: err}
	} else {
		results <- result{url: buildOutputURL(obj, conf)}
	}
}
开发者ID:carlosgaldino,项目名称:s3-upload,代码行数:27,代码来源:main.go

示例4: UploadObject

func UploadObject(svc *s3.S3, bucketName, objKey string, reader io.Reader) error {
	params := &s3.PutObjectInput{
		Body:   aws.ReadSeekCloser(reader),
		Bucket: aws.String(bucketName),
		Key:    aws.String(objKey),
		ACL:    ACLPublicRead,
	}
	_, err := svc.PutObject(params)
	return err
}
开发者ID:smothiki,项目名称:sa-builder,代码行数:10,代码来源:object.go

示例5: put

func put(service *s3.S3, bucketName string, key, path string) {
	f, err := os.Open(path)
	if err != nil {
		panic(err)
	}
	defer f.Close()

	_, err = service.PutObject(&s3.PutObjectInput{
		Bucket: stringPtr(bucketName),
		Key:    stringPtr(key),
		Body:   f,
	})
	if err != nil {
		panic(err)
	}
}
开发者ID:glyn,项目名称:bloblets,代码行数:16,代码来源:blobstore.go

示例6: s3Upload

func s3Upload(svc *s3.S3, bucket string, filename string, data []byte, date string) (*s3.PutObjectOutput, error) {
	params := &s3.PutObjectInput{
		Bucket: aws.String(bucket),
		Key:    aws.String(filename),
		Body:   bytes.NewReader(data),
		ACL:    aws.String("public-read"),
		Metadata: map[string]*string{
			"Date": aws.String(date), //required
		},
	}
	resp, err := svc.PutObject(params)
	if err != nil {
		log.Printf("Error uploading to s3: %v", err)
		log.Printf("bucket: %s filename: %s date: %s", bucket, filename, date)
	}

	return resp, err
}
开发者ID:csima,项目名称:attachments,代码行数:18,代码来源:amazon.go

示例7: putObject

func putObject(svc *s3.S3, k string, b []byte) error {
	var err error
	if c.Conf.GZIP {
		if b, err = gz(b); err != nil {
			return err
		}
		k = k + ".gz"
	}

	if _, err := svc.PutObject(&s3.PutObjectInput{
		Bucket: &c.Conf.S3Bucket,
		Key:    &k,
		Body:   bytes.NewReader(b),
	}); err != nil {
		return fmt.Errorf("Failed to upload data to %s/%s, %s",
			c.Conf.S3Bucket, k, err)
	}
	return nil
}
开发者ID:ymomoi,项目名称:vuls,代码行数:19,代码来源:s3.go

示例8: putObject

func putObject(client *s3.S3, bucket string, key string, body []byte, contentType string) (err error) {
	contentLength := int64(len(body))

	request := &s3.PutObjectInput{
		Body:          bytesReadCloser{bytes.NewReader(body)},
		Bucket:        &bucket,
		ContentLength: &contentLength,
		ContentType:   &contentType,
		Key:           &key,
	}

	if client == nil {
		return
	}

	if _, err = client.PutObject(request); err != nil {
		err = fmt.Errorf("S3 PutObject: %s", err)
	}
	return
}
开发者ID:ninchat,项目名称:nameq,代码行数:20,代码来源:storage.go

示例9: ZipUploadReaderD

func (s *S3) ZipUploadReaderD(S3 *s3.S3, key string, data io.Reader, contentType, perm string) (*s3.PutObjectInput, *s3.PutObjectOutput, error) {

	b := &bytes.Buffer{}
	gz := gzip.NewWriter(b)
	_, err := io.Copy(gz, data)
	if err != nil {
		return nil, nil, err
	}
	gz.Close()

	req := &s3.PutObjectInput{
		ACL:         &perm,                      // aws.StringValue   `xml:"-"` private | public-read | public-read-write | authenticated-read | bucket-owner-read | bucket-owner-full-control
		Body:        bytes.NewReader(b.Bytes()), // io.ReadSeeker     `xml:"-"`
		Bucket:      &s.Bucket,                  // aws.StringValue   `xml:"-"`
		ContentType: &contentType,               // aws.StringValue   `xml:"-"`
		Key:         &key,                       // aws.StringValue   `xml:"-"`
	}
	res, err := S3.PutObject(req)
	return req, res, err
}
开发者ID:masahide,项目名称:goansible,代码行数:20,代码来源:s3.go


注:本文中的github.com/aws/aws-sdk-go/service/s3.S3.PutObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。