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