本文整理汇总了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
}
示例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)
}
}
}
示例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)}
}
}
示例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
}
示例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)
}
}
示例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
}
示例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
}
示例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
}
示例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
}