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


Golang s3.Bucket类代码示例

本文整理汇总了Golang中launchpad/net/goamz/s3.Bucket的典型用法代码示例。如果您正苦于以下问题:Golang Bucket类的具体用法?Golang Bucket怎么用?Golang Bucket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: putFiles

func putFiles(bucket *s3.Bucket, c <-chan *Item) {
	var wg sync.WaitGroup
	wg.Add(options.Concurrency)
	for i := 0; i < options.Concurrency; i++ {
		go func() {
			for item := range c {
				func() {
					f, err := os.Open(item.Path)
					if err != nil {
						log.Printf("Pushing %s failed: %s", item.Path, err)
					}
					defer f.Close()

					path := item.Path[len(item.Prefix)+1:]
					err = bucket.PutReader(options.Put.Prefix+path, f, item.FileInfo.Size(), mime.TypeByExtension(filepath.Ext(item.Path)), s3.BucketOwnerFull)
					if err != nil {
						log.Printf("Uploading %s failed: %s", path, err)
						return
					}
					log.Printf("Uploading %s done", path)
				}()
			}
			wg.Done()
		}()
	}
	wg.Wait()
}
开发者ID:HealPay,项目名称:s3put,代码行数:27,代码来源:s3put.go

示例2: generateThumbnails

func generateThumbnails(file multipart.File, userId, pathPrefix string, bucket *s3.Bucket) error {
	file.Seek(0, 0)

	img, _, err := image.Decode(file)
	if err != nil {
		log.Println("Error decoding image", err)
		return err
	}

	var buf bytes.Buffer
	for _, i := range THUMBNAIL_SIZES {
		resized := resize.Resize(uint(i), 0, img, resize.Lanczos3)
		err = jpeg.Encode(&buf, resized, nil)
		if err != nil {
			return err
		}
		path := fmt.Sprintf("%s/%d.jpg", pathPrefix, i)
		err = bucket.Put(path, buf.Bytes(), "image/jpeg", s3.PublicRead)
		if err != nil {
			return err
		}
		buf.Reset()
	}

	return err
}
开发者ID:AndrewJHart,项目名称:irlmoji,代码行数:26,代码来源:handlers_upload.go

示例3: hashRemote

func hashRemote(bucket *s3.Bucket, path string) []byte {
	file, err := bucket.GetReader(path)
	if err != nil {
		return nil
	}
	return hashFile(file)
}
开发者ID:rossdylan,项目名称:3sync,代码行数:7,代码来源:3sync.go

示例4: listBucketFiles

func listBucketFiles(bucket *s3.Bucket) <-chan *Item {
	c := make(chan *Item)
	go func() {
		marker := ""
		for {
			resp, err := bucket.List(options.Get.Prefix, "", marker, 1000)
			if err != nil {
				log.Printf("Could not list items in bucket: %s", err)
			}
			for _, item := range resp.Contents {
				c <- &Item{
					Prefix:   options.Get.Prefix,
					Path:     item.Key,
					FileInfo: nil,
				}
				marker = item.Key
			}
			if !resp.IsTruncated {
				break
			}
		}
		close(c)
	}()
	return c
}
开发者ID:HealPay,项目名称:s3put,代码行数:25,代码来源:s3put.go

示例5: Get

func Get(file string, bucket *s3.Bucket, path string) {
	data, err := bucket.Get(path)
	if err != nil {
		panic(err.Error())
	}
	perms := os.FileMode(0644)

	err = ioutil.WriteFile(file, data, perms)
	if err != nil {
		panic(err.Error())
	}
}
开发者ID:kristofer,项目名称:gosync,代码行数:12,代码来源:s3.go

示例6: upload

func upload(directory string, f os.FileInfo, bucket *s3.Bucket, permission s3.ACL) {
	log.Println("uploading " + f.Name())
	data, err := ioutil.ReadFile(path.Join(directory, f.Name()))
	if err != nil {
		panic(err.Error())
	}
	err = bucket.Put(f.Name(), data, "", permission)
	if err != nil {
		panic(err.Error())
	}
	log.Println("finished uploading " + f.Name())
}
开发者ID:heidar,项目名称:s3upload,代码行数:12,代码来源:s3upload.go

示例7: upload

func upload(bucket *s3.Bucket, checksum, filename string) {
	f, err := os.Open(filename)
	handleErr(err)
	defer f.Close()
	path := fmt.Sprintf("%s/%s", checksum, filename)
	fi, err := f.Stat()
	handleErr(err)
	err = bucket.PutReader(path, f, fi.Size(), "binary/octet-stream", s3.PublicRead)
	if err != nil {
		log.Fatalf("Go makes me sad because of: %s", err)
	}
	log.Printf("Uploaded %s", path)
}
开发者ID:justinabrahms,项目名称:gatherer,代码行数:13,代码来源:main.go

示例8: Put

func Put(bucket *s3.Bucket, path string, file string) {
	contType := "binary/octet-stream"
	Perms := s3.ACL("private")

	data, err := ioutil.ReadFile(file)
	if err != nil {
		panic(err.Error())
	}

	err = bucket.Put(path, data, contType, Perms)
	if err != nil {
		panic(err.Error())
	}
}
开发者ID:kristofer,项目名称:gosync,代码行数:14,代码来源:s3.go

示例9: killBucket

func killBucket(b *s3.Bucket) {
	var err error
	for attempt := attempts.Start(); attempt.Next(); {
		err = b.DelBucket()
		if err == nil {
			return
		}
		if _, ok := err.(*net.DNSError); ok {
			return
		}
		e, ok := err.(*s3.Error)
		if ok && e.Code == "NoSuchBucket" {
			return
		}
		if ok && e.Code == "BucketNotEmpty" {
			// Errors are ignored here. Just retry.
			resp, err := b.List("", "", "", 1000)
			if err == nil {
				for _, key := range resp.Contents {
					_ = b.Del(key.Key)
				}
			}
			multis, _, _ := b.ListMulti("", "")
			for _, m := range multis {
				_ = m.Abort()
			}
		}
	}
	message := "cannot delete test bucket"
	if err != nil {
		message += ": " + err.Error()
	}
	panic(message)
}
开发者ID:whyrusleeping,项目名称:gobuilder,代码行数:34,代码来源:s3i_test.go

示例10: GetReader

func GetReader(b *s3.Bucket, path string) (reader *TweetReader, err error) {
	body, err := b.GetReader(path)
	if err != nil {
		return nil, err
	}

	gr, err := gzip.NewReader(body)
	if err != nil {
		return nil, err
	}

	reader = NewTweetReaderSerial(bufio.NewReaderSize(gr, 16*4096))

	return reader, err
}
开发者ID:eikeon,项目名称:tweet,代码行数:15,代码来源:tweet.go

示例11: send

// Sends this upload to the given S3 bucket
func (u *Upload) send(b *s3.Bucket) error {
	f, err := os.Open(u.LocalFile)
	if err != nil {
		return err
	}
	defer f.Close()

	info, err := os.Stat(u.LocalFile)
	if err != nil {
		return err
	}

	r := bufio.NewReader(f)
	err = b.PutReader(u.RemoteFile, r, info.Size(), u.GetContentType(), u.Access)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:postfix,项目名称:s3upload,代码行数:21,代码来源:upload.go

示例12: getFiles

func getFiles(bucket *s3.Bucket, c <-chan *Item) {
	var wg sync.WaitGroup
	wg.Add(options.Concurrency)
	for i := 0; i < options.Concurrency; i++ {
		go func() {
			for item := range c {
				func() {
					itempath := item.Path[len(item.Prefix):]
					dirname, fname := filepath.Split(itempath)
					dirname = filepath.Join(options.Remainder[0], dirname)

					err := os.MkdirAll(dirname, os.FileMode(0755))
					if err != nil {
						log.Printf("Could not create target folder %s: %s", dirname, err)
						return
					}

					f, err := os.Create(filepath.Join(dirname, fname))
					if err != nil {
						log.Printf("Opening %s failed: %s", item.Path, err)
						return
					}
					defer f.Close()

					rc, err := bucket.GetReader(item.Path)
					if err != nil {
						log.Printf("Downloading %s failed: %s", item.Path, err)
						return
					}
					defer rc.Close()
					io.Copy(f, rc)
					log.Printf("Downloading %s done", item.Path)
				}()
			}
			wg.Done()
		}()
	}
	wg.Wait()
}
开发者ID:HealPay,项目名称:s3put,代码行数:39,代码来源:s3put.go

示例13: syncPath

func syncPath(acl, localPath, path string, bucket *s3.Bucket) {
	s3Path := strings.Replace(path, localPath, "", -1)
	file, err := os.Open(path)
	if err != nil {
		fmt.Println("Error opening local file, Failed to sync '" + path + "'")
		return
	}
	info, err := file.Stat()
	if err != nil {
		fmt.Println("Error stating local file, Failed to sync '" + path + "'")
		return
	}
	length := info.Size()
	pathSplit := strings.Split(path, ".")
	ext := pathSplit[len(pathSplit)-1]
	mtype := mime.TypeByExtension(ext)
	puterr := bucket.PutReader(s3Path, file, length, mtype, s3.ACL(acl))
	if puterr != nil {
		fmt.Println("Failed to sync: " + s3Path)
		return
	}
	fmt.Println("Synced: " + s3Path)

}
开发者ID:rossdylan,项目名称:3sync,代码行数:24,代码来源:3sync.go


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