diff --git a/s3/s3.go b/s3/s3.go index f2639419b18db2e7449335b82db8f724fabac981..682a932d0be4996df247e2f258ed0d8a41fc01f4 100644 --- a/s3/s3.go +++ b/s3/s3.go @@ -133,6 +133,29 @@ func (s SessionWithHelpers) UploadWithExpiry(data []byte, bucket, fileName strin return s.GetSignedDownloadURL(bucket, fileName, 24*time.Hour, isDebug) } +// UploadTempFile upload a file to S3 that will be automatically deleted after the expireDate +func (s SessionWithHelpers) UploadTempFile(data []byte, bucket, fileName string, metadata *map[string]*string, expireDate *time.Time) (*s3.PutObjectOutput, error) { + mimeType := getTypeForFilename(fileName) + putInput := &s3.PutObjectInput{ + Bucket: aws.String(bucket), + Key: aws.String(fileName), + ContentType: aws.String(string(mimeType)), + Body: bytes.NewReader(data), + Expires: expireDate, + } + + if metadata != nil { + putInput.Metadata = *metadata + } + + response, err := s.S3Session.PutObject(putInput) + if err != nil { + return nil, err + } + + return response, nil +} + // GetSignedDownloadURL gets a signed download URL for the duration. If scv is nil, a new session will be created. func (s SessionWithHelpers) GetSignedDownloadURL(bucket string, fileName string, duration time.Duration, isDebug bool) (string, error) { getInput := &s3.GetObjectInput{