Exemplo n.º 1
0
func UploadFile(uploader *s3manager.Uploader, bucket string, path string, contentType string, file *os.File) {
	_, err := uploader.Upload(&s3manager.UploadInput{
		Bucket:      &bucket,
		Key:         aws.String(path),
		Body:        file,
		ContentType: &contentType,
	})
	if err != nil {
		log.Fatalln("Failed to upload", path, err)
	}
}
Exemplo n.º 2
0
func uploadFile(uploader s3manager.Uploader, key string, file io.Reader) {
	resp, err := uploader.Upload(&s3manager.UploadInput{
		Bucket: aws.String(*bucket),
		Key:    aws.String(key),
		Body:   file,
	})
	if err != nil {
		log.Println("Failed to upload a file because of: ", err)
		return
	}
	log.Println("File was successfully uploaded! Location:", resp.Location)
}
Exemplo n.º 3
0
func handleCreate(watcher *fsnotify.Watcher, u *s3manager.Uploader, path string) error {
	fi, _ := os.Lstat(path)

	if fi.IsDir() {
		return watcher.Add(path)
	}

	r, err := os.Open(path)
	if err != nil {
		log.Fatal(err)
		return err
	}

	name := fi.Name()
	_, err = u.Upload(&s3manager.UploadInput{
		Bucket: &os.Args[2],
		Body:   r,
		Key:    &name,
	})
	if err != nil {
		log.Fatal(err)
	}
	return nil
}