Skip to content
Snippets Groups Projects
Select Git revision
  • dd429726b9474dad9c90ef0b4b98d72f9abe0c94
  • dev default protected
  • prod protected
  • 1.0.58
  • 1.0.57
  • 1.0.52
  • 1.0.56
  • 1.0.51
  • 1.0.50
  • 1.0.33
  • 1.0.32
  • 1.0.31
  • 1.0.30
  • 1.0.29
  • 1.0.28
  • 1.0.27
  • 1.0.26
  • 1.0.25
  • 1.0.24
  • 1.0.23
  • 1.0.22
  • 1.0.21
  • 1.0.20
23 results

Readme.md

Blame
  • s3.go 7.23 KiB
    package s3
    
    import (
    	"bytes"
    	"encoding/binary"
    	"fmt"
    	"net/url"
    	"path"
    	"strings"
    	"time"
    
    	"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 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/*"
    
    	// 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 SessionWithHelpers struct {
    	S3Session *s3.S3
    }
    
    func NewSession(session *session.Session) *SessionWithHelpers {
    	return &SessionWithHelpers{
    		S3Session: s3.New(session),
    	}
    }
    
    func (s SessionWithHelpers) Upload(data []byte, bucket, fileName string, metadata *map[string]*string, isDebug bool) (*s3.PutObjectOutput, error) {
    	mimeType := getTypeForFilename(fileName)
    	putInput := &s3.PutObjectInput{