s3

package
v1.241.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2024 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	S3ExpiryDuration1Day  time.Duration = 24 * time.Hour
	S3ExpiryDuration7Days time.Duration = 7 * 24 * time.Hour
)

Duration constants

Variables

View Source
var (
	ErrorS3ClientNotEstablished = errors.Error("could not establish an S3 client")
)

Functions

func GetS3CredentialsProvider added in v1.226.0

func GetS3CredentialsProvider(isDebug bool) credentials.StaticCredentialsProvider

func GetS3FileKey

func GetS3FileKey(fileName string, folder string) string

func URLFromFileName

func URLFromFileName(region string, bucket string, fileName string) string

Types

type ClientWithHelpers added in v1.226.0

type ClientWithHelpers struct {
	S3Client *s3.Client
}

func GetClient added in v1.226.0

func GetClient(isDebug bool, region ...string) *ClientWithHelpers

GetClient gets an S3 client for the specified region. This function should never return a nil response.

func NewClient added in v1.226.0

func NewClient(cfg aws.Config) *ClientWithHelpers

func (ClientWithHelpers) CopyObjectBucketToBucket added in v1.226.0

func (s ClientWithHelpers) CopyObjectBucketToBucket(sourceBucket string, destinationBucket string, sourceFileName string, destinationFilename string, settings S3UploadSettings) error

CopyObjectBucketToBucket - Copy an object from one S3 bucket to another

func (ClientWithHelpers) DeleteObjectFromBucket added in v1.226.0

func (s ClientWithHelpers) DeleteObjectFromBucket(bucket string, fileName string) error

DeleteObjectFromBucket - Delete an object from an S3 bucket

func (ClientWithHelpers) FileExists added in v1.226.0

func (s ClientWithHelpers) FileExists(bucket string, fileName string) (bool, error)

func (ClientWithHelpers) GetObject added in v1.226.0

func (s ClientWithHelpers) GetObject(bucket string, fileName string, isDebug bool) (*s3.GetObjectOutput, error)

func (ClientWithHelpers) GetObjectMetadata added in v1.226.0

func (s ClientWithHelpers) GetObjectMetadata(bucket string, fileName string, isDebug bool) (map[string]string, error)

func (ClientWithHelpers) GetSignedDownloadURL added in v1.226.0

func (s ClientWithHelpers) GetSignedDownloadURL(bucket string, fileName string, duration time.Duration, headers ...map[string]string) (string, error)

GetSignedDownloadURL gets a signed download URL for the duration. If scv is nil, a new session will be created.

func (ClientWithHelpers) GetSignedUploadURL added in v1.226.0

func (s ClientWithHelpers) GetSignedUploadURL(bucket string, fileName string, duration time.Duration) (string, error)

GetSignedUploadURL gets a signed upload URL for the duration. If scv is nil, a new session will be created.

func (ClientWithHelpers) MoveObjectBucketToBucket added in v1.226.0

func (s ClientWithHelpers) MoveObjectBucketToBucket(sourceBucket string, destinationBucket string, sourceFileName string, destinationFileName string, settings S3UploadSettings) error

MoveObjectBucketToBucket - Move object from one S3 bucket to another

func (ClientWithHelpers) Upload added in v1.226.0

func (s ClientWithHelpers) Upload(data []byte, bucket, fileName string, metadata *map[string]string) (*s3.PutObjectOutput, error)

func (ClientWithHelpers) UploadWith1DayExpiry added in v1.226.0

func (s ClientWithHelpers) UploadWith1DayExpiry(data []byte, bucket, fileName string, mimeType MIMEType, shouldDownloadInsteadOfOpen bool) (string, error)

func (ClientWithHelpers) UploadWithFileExtension added in v1.226.0

func (s ClientWithHelpers) UploadWithFileExtension(data []byte, bucket, filePrefix, fileExt string, mimeType MIMEType) (*S3UploadResponse, error)

UploadWithFileExtension will upload a file to S3 and return a standard S3UploadResponse.

func (ClientWithHelpers) UploadWithSettings added in v1.226.0

func (s ClientWithHelpers) UploadWithSettings(data []byte, bucket, fileName string, settings S3UploadSettings) (string, error)

func (ClientWithHelpers) UploadWithSettingsRevised added in v1.226.0

func (s ClientWithHelpers) UploadWithSettingsRevised(data []byte, bucket string, settings S3UploadSettings) (S3UploadResponse, error)

UploadWithSettingsRevised can be renamed to UploadWithSettings once original function has been deprecated.

type MIMEType

type MIMEType string
const (
	// MIMETypePDF defines the constant for the PDF MIME type.
	MIMETypePDF MIMEType = "application/pdf"

	// MIMETypeCSV defines the constant for the CSV MIME type.
	MIMETypeCSV MIMEType = "text/csv"

	// MIMETypeZIP defines the constant for the ZIP MIME type.
	MIMETypeZIP MIMEType = "application/zip"

	// MIMETypeJSON defines the constant for the JSON MIME type.
	MIMETypeJSON MIMEType = "application/json"

	// MIMETypeText defines the constant for the Plain text MIME type.
	MIMETypeText MIMEType = "text/plain"

	// MIMETypeImage defines the constant for the Image MIME type.
	MIMETypeImage MIMEType = "image/*"

	// MIMETypePNG defines the constant for the PNG MIME type.
	MIMETypePNG MIMEType = "image/png"

	// MIMETypeDefault defines the constant for the default MIME type.
	MIMETypeDefault MIMEType = "application/octet-stream"

	// TypeXLS defines the constant for the XLS MIME type.
	MIMETypeXLS MIMEType = "application/vnd.ms-excel"

	// TypeXLSX defines the constant for the XLSX MIME type.
	MIMETypeXLSX MIMEType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
)

type S3UploadResponse

type S3UploadResponse struct {
	URL      string `json:"url"`
	Filename string `json:"filename"`
	Bucket   string `json:"bucket"`
	FileSize int    `json:"file_size"`
}

S3UploadResponse defines the structure of a standard JSON response to a PDF/CSV/etc request.

type S3UploadSettings

type S3UploadSettings struct {
	MimeType              MIMEType
	RetrieveSignedUrl     bool
	ExpiryDuration        *time.Duration // Used to set expiry datetime of download links. NB: does not affect deletion of object from S3 bucket.
	AddContentDisposition bool
	FilePath              string
	FileName              string
	FileExt               string
	InsertUUID            bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL