Select Git revision
-
James Page authored
#29 Explicitly set trailing slash for FilePath in UploadWithSettingsRevised so that folder path string constants don't need to change.
James Page authored#29 Explicitly set trailing slash for FilePath in UploadWithSettingsRevised so that folder path string constants don't need to change.
s3.go 12.44 KiB
package s3
import (
"bytes"
"encoding/binary"
"fmt"
"net/url"
"path"
"strings"
"time"
"github.com/aws/aws-sdk-go/aws/awserr"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/errors"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/google/uuid"
)
// S3UploadResponse defines the structure of a standard JSON response to a PDF/CSV/etc request.
type S3UploadResponse struct {
URL string `json:"url"`
Filename string `json:"filename"`
Bucket string `json:"bucket"`
FileSize int `json:"file_size"`
}
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
}
// Duration constants
const (
S3ExpiryDuration1Day time.Duration = 24 * time.Hour
S3ExpiryDuration7Days time.Duration = 7 * 24 * time.Hour
)
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"