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


Golang Bucket.PutReader方法代碼示例

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


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

示例3: 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

示例4: 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.PutReader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。