本文整理匯總了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)
}