Exemple #1
0
func s3UploadFileReader(pathRemote, pathLocal string, public bool) error {
	fmt.Printf("Uploading '%s' as '%s'. ", pathLocal, pathRemote)
	start := time.Now()
	opts := s3.Options{}
	opts.ContentMD5 = md5B64OfFile(pathLocal)
	bucket := s3GetBucket()
	mimeType := mime.TypeByExtension(filepath.Ext(pathLocal))
	fileSize := fileSizeMust(pathLocal)
	perm := s3.Private
	if public {
		perm = s3.PublicRead
	}
	f, err := os.Open(pathLocal)
	if err != nil {
		return err
	}
	defer f.Close()
	err = bucket.PutReader(pathRemote, f, fileSize, mimeType, perm, opts)
	appendTiming(time.Since(start), fmt.Sprintf("Upload of %s, size: %d", pathRemote, fileSize))
	if err != nil {
		fmt.Printf("Failed with %s\n", err)
	} else {
		fmt.Printf("Done in %s\n", time.Since(start))
	}
	return err
}
Exemple #2
0
func uploadFileInfo(fi *FileInfo) {
	timeStart := time.Now()
	pathRemote := fi.S3FullPath
	pathLocal := fi.Path
	fmt.Printf("uploadFileInfo(): %s => %s, pub: %v, %d bytes", pathLocal, pathRemote, isPublic(), fi.Size)
	if sha1ExistsInS3Must(fi.Sha1Hex) {
		// TODO: if different permissions (public vs. private), change the perms
		// TODO: for extra paranoia could verify that fi.Size matches size in S3
		fmt.Printf("  skipping because already exists\n")
		return
	}
	bucket := s3GetBucket()
	d, err := ioutil.ReadFile(pathLocal)
	fataliferr(err)
	mimeType := mime.TypeByExtension(filepath.Ext(pathLocal))
	perm := s3.Private
	if isPublic() {
		perm = s3.PublicRead
	}
	opts := s3.Options{}
	opts.Meta = make(map[string][]string)
	opts.Meta["name"] = []string{filepath.Base(pathLocal)}
	opts.ContentMD5 = fi.Md5B64
	err = bucket.Put(pathRemote, d, mimeType, perm, opts)
	fataliferr(err)
	fmt.Printf(" took %s\n", time.Since(timeStart))
}
Exemple #3
0
// Put puts a serialize.Msgpack object into bucket b.
// by default uploads checksum of the files
func Put(b *s3.Bucket, data []byte, path string, checksum string) error {
	// data is a log of msgpack file kind
	// aws api wants []byte
	options := s3.Options{}
	options.ContentMD5 = checksum
	err := b.Put(path, data, "", s3.Private, options)
	if err != nil {
		return err
	}
	return nil
}
Exemple #4
0
func s3UploadString(pathRemote string, s string, public bool) error {
	fmt.Printf("Uploading string of length %d  as '%s'\n", len(s), pathRemote)
	bucket := s3GetBucket()
	d := []byte(s)
	mimeType := mime.TypeByExtension(filepath.Ext(pathRemote))
	opts := s3.Options{}
	opts.ContentMD5 = md5B64OfBytes([]byte(s))
	perm := s3.Private
	if public {
		perm = s3.PublicRead
	}
	return bucket.Put(pathRemote, d, mimeType, perm, opts)
}
Exemple #5
0
func s3UploadFile(pathRemote, pathLocal string, public bool) error {
	fmt.Printf("Uploading '%s' as '%s'\n", pathLocal, pathRemote)
	bucket := s3GetBucket()
	d, err := ioutil.ReadFile(pathLocal)
	if err != nil {
		return err
	}
	perm := s3.Private
	if public {
		perm = s3.PublicRead
	}
	mimeType := mime.TypeByExtension(filepath.Ext(pathLocal))
	opts := s3.Options{}
	opts.ContentMD5 = md5B64OfBytes(d)
	return bucket.Put(pathRemote, d, mimeType, perm, opts)
}