Skip to content
Snippets Groups Projects
Commit cbbcb587 authored by Johan de Klerk's avatar Johan de Klerk
Browse files

Upload a temp file to s3

parent d0a7bec9
No related branches found
No related tags found
No related merge requests found
......@@ -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{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment