[GH-ISSUE #67] Support for storage class #57

Open
opened 2026-02-26 21:34:13 +03:00 by kerem · 0 comments
Owner

Originally created by @LombardiDaniel on GitHub (Dec 11, 2024).
Original GitHub issue: https://github.com/eduardolat/pgbackweb/issues/67

Support for storage class when creating a backup destination, on the internal/integration/storage/s3.go it would be a simple change:

func (Client) S3Upload(
	accessKey, secretKey, region, endpoint, bucketName, storageClass, key string,
	fileReader io.Reader,
) (int64, error) {
	s3Client, err := createS3Client(
		accessKey, secretKey, region, endpoint,
	)
	if err != nil {
		return 0, err
	}

	key = strutil.RemoveLeadingSlash(key)
	contentType := strutil.GetContentTypeFromFileName(key)

	uploader := s3manager.NewUploaderWithClient(s3Client)
	_, err = uploader.Upload(&s3manager.UploadInput{
		Bucket:       aws.String(bucketName),
		Key:          aws.String(key),
		Body:         fileReader,
		ContentType:  aws.String(contentType),
		StorageClass: aws.String(storageClass),
	})
	if err != nil {
		return 0, fmt.Errorf("failed to upload file to S3: %w", err)
	}

	fileHead, err := s3Client.HeadObject(&s3.HeadObjectInput{
		Bucket: aws.String(bucketName),
		Key:    aws.String(key),
	})
	if err != nil {
		return 0, fmt.Errorf("failed to get uploaded file info from S3: %w", err)
	}
	fileSize := *fileHead.ContentLength

	return fileSize, nil
}

Didn't really look into much more than that though

Originally created by @LombardiDaniel on GitHub (Dec 11, 2024). Original GitHub issue: https://github.com/eduardolat/pgbackweb/issues/67 Support for storage class when creating a backup destination, on the [internal/integration/storage/s3.go](https://github.com/eduardolat/pgbackweb/internal/integration/storage/s3.go) it would be a simple change: ```go func (Client) S3Upload( accessKey, secretKey, region, endpoint, bucketName, storageClass, key string, fileReader io.Reader, ) (int64, error) { s3Client, err := createS3Client( accessKey, secretKey, region, endpoint, ) if err != nil { return 0, err } key = strutil.RemoveLeadingSlash(key) contentType := strutil.GetContentTypeFromFileName(key) uploader := s3manager.NewUploaderWithClient(s3Client) _, err = uploader.Upload(&s3manager.UploadInput{ Bucket: aws.String(bucketName), Key: aws.String(key), Body: fileReader, ContentType: aws.String(contentType), StorageClass: aws.String(storageClass), }) if err != nil { return 0, fmt.Errorf("failed to upload file to S3: %w", err) } fileHead, err := s3Client.HeadObject(&s3.HeadObjectInput{ Bucket: aws.String(bucketName), Key: aws.String(key), }) if err != nil { return 0, fmt.Errorf("failed to get uploaded file info from S3: %w", err) } fileSize := *fileHead.ContentLength return fileSize, nil } ``` Didn't really look into much more than that though
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/pgbackweb#57
No description provided.