// Save writes data to given store
Save writes data to given store
// Save writes data to given store
func Save(data io.Reader, stg pbm.Storage, name string) error {
	switch stg.Type {
	case pbm.StorageFilesystem:
		filepath := path.Join(stg.Filesystem.Path, name)
		fw, err := os.Create(filepath)
		if err != nil {
			return errors.Wrapf(err, "create destination file <%s>", filepath)
		}
		_, err = io.Copy(fw, data)
		return errors.Wrap(err, "write to file")
	case pbm.StorageS3:
		switch stg.S3.Provider {
		default:
			awsSession, err := session.NewSession(&aws.Config{
				Region:   aws.String(stg.S3.Region),
				Endpoint: aws.String(stg.S3.EndpointURL),
				Credentials: credentials.NewStaticCredentials(
					stg.S3.Credentials.AccessKeyID,
					stg.S3.Credentials.SecretAccessKey,
					"",
				),
				S3ForcePathStyle: aws.Bool(true),
			})
			if err != nil {
				return errors.Wrap(err, "create AWS session")
			}
			_, err = s3manager.NewUploader(awsSession, func(u *s3manager.Uploader) {
				u.PartSize = 32 * 1024 * 1024 
				u.LeavePartsOnError = true    
				u.Concurrency = 1
			}).Upload(&s3manager.UploadInput{
				Bucket: aws.String(stg.S3.Bucket),
				Key:    aws.String(path.Join(stg.S3.Prefix, name)),
				Body:   data,
			})
			return errors.Wrap(err, "upload to S3")
		case pbm.S3ProviderGCS:
			mc, err := minio.NewWithRegion(pbm.GCSEndpointURL, stg.S3.Credentials.AccessKeyID, stg.S3.Credentials.SecretAccessKey, true, stg.S3.Region)
			if err != nil {
				return errors.Wrap(err, "NewWithRegion")
			}
			_, err = mc.PutObject(stg.S3.Bucket, path.Join(stg.S3.Prefix, name), data, -1, minio.PutObjectOptions{})
			return errors.Wrap(err, "upload to GCS")
		}
	default:
		return errors.New("unknown storage type")
	}
}
func Save ( data io . Reader , stg pbm . Storage , name string ) error { switch stg . Type { case pbm . StorageFilesystem : filepath := path . Join ( stg . Filesystem . Path , name ) fw , err := os . Create ( filepath ) if err != nil { return errors . Wrapf ( err , " " , filepath ) } _ , err = io . Copy ( fw , data ) return errors . Wrap ( err , " " ) case pbm . StorageS3 : switch stg . S3 . Provider { default : awsSession , err := session . NewSession ( & aws . Config { Region : aws . String ( stg . S3 . Region ) , Endpoint : aws . String ( stg . S3 . EndpointURL ) , Credentials : credentials . NewStaticCredentials ( stg . S3 . Credentials . AccessKeyID , stg . S3 . Credentials . SecretAccessKey , " " , ) , S3ForcePathStyle : aws . Bool ( true ) , } ) if err != nil { return errors . Wrap ( err , " " ) } _ , err = s3manager . NewUploader ( awsSession , func ( u * s3manager . Uploader ) { u . PartSize = 32 * 1024 * 1024 u . LeavePartsOnError = true u . Concurrency = 1 } ) . Upload ( & s3manager . UploadInput { Bucket : aws . String ( stg . S3 . Bucket ) , Key : aws . String ( path . Join ( stg . S3 . Prefix , name ) ) , Body : data , } ) return errors . Wrap ( err , " " ) case pbm . S3ProviderGCS : mc , err := minio . NewWithRegion ( pbm . GCSEndpointURL , stg . S3 . Credentials . AccessKeyID , stg . S3 . Credentials . SecretAccessKey , true , stg . S3 . Region ) if err != nil { return errors . Wrap ( err , " " ) } _ , err = mc . PutObject ( stg . S3 . Bucket , path . Join ( stg . S3 . Prefix , name ) , data , - 1 , minio . PutObjectOptions { } ) return errors . Wrap ( err , " " ) } default : return errors . New ( " " ) } }
Save writes data to given store
Save writes data to given store
// 32MB part size // Don't delete the parts if the upload fails. // using minio client with GCS because it // allows to disable chuncks muiltipertition for upload