Esempio n. 1
0
func generateThumbnails(file multipart.File, userId, pathPrefix string, bucket *s3.Bucket) error {
	file.Seek(0, 0)

	img, _, err := image.Decode(file)
	if err != nil {
		log.Println("Error decoding image", err)
		return err
	}

	var buf bytes.Buffer
	for _, i := range THUMBNAIL_SIZES {
		resized := resize.Resize(uint(i), 0, img, resize.Lanczos3)
		err = jpeg.Encode(&buf, resized, nil)
		if err != nil {
			return err
		}
		path := fmt.Sprintf("%s/%d.jpg", pathPrefix, i)
		err = bucket.Put(path, buf.Bytes(), "image/jpeg", s3.PublicRead)
		if err != nil {
			return err
		}
		buf.Reset()
	}

	return err
}
Esempio n. 2
0
func upload(directory string, f os.FileInfo, bucket *s3.Bucket, permission s3.ACL) {
	log.Println("uploading " + f.Name())
	data, err := ioutil.ReadFile(path.Join(directory, f.Name()))
	if err != nil {
		panic(err.Error())
	}
	err = bucket.Put(f.Name(), data, "", permission)
	if err != nil {
		panic(err.Error())
	}
	log.Println("finished uploading " + f.Name())
}
Esempio n. 3
0
func Put(bucket *s3.Bucket, path string, file string) {
	contType := "binary/octet-stream"
	Perms := s3.ACL("private")

	data, err := ioutil.ReadFile(file)
	if err != nil {
		panic(err.Error())
	}

	err = bucket.Put(path, data, contType, Perms)
	if err != nil {
		panic(err.Error())
	}
}