S3 API File Uploads #1
|
@ -155,7 +155,7 @@ func (h *Handler) fetch(resp http.ResponseWriter, req *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if h.Cdn != "" {
|
if h.Cdn != "" {
|
||||||
resp.Header().Set("Location", h.Cdn + "/" + filename)
|
resp.Header().Set("Location", h.Cdn+"/"+filename)
|
||||||
resp.WriteHeader(http.StatusCreated)
|
resp.WriteHeader(http.StatusCreated)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -293,7 +293,7 @@ func (h *Handler) store(resp http.ResponseWriter, req *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if h.Cdn != "" {
|
if h.Cdn != "" {
|
||||||
resp.Header().Set("Location", h.Cdn + "/" + outFilename)
|
resp.Header().Set("Location", h.Cdn+"/"+outFilename)
|
||||||
} else {
|
} else {
|
||||||
resp.Header().Set("Location", "/uploads/"+outFilename)
|
resp.Header().Set("Location", "/uploads/"+outFilename)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go-v2/config"
|
|
||||||
"github.com/aws/aws-sdk-go-v2/aws"
|
"github.com/aws/aws-sdk-go-v2/aws"
|
||||||
|
"github.com/aws/aws-sdk-go-v2/config"
|
||||||
awss3 "github.com/aws/aws-sdk-go-v2/service/s3"
|
awss3 "github.com/aws/aws-sdk-go-v2/service/s3"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
@ -41,15 +41,15 @@ func (s *s3) store(r io.Reader, username string, mimeType string, basename strin
|
||||||
|
|
||||||
s3client := awss3.NewFromConfig(cfg)
|
s3client := awss3.NewFromConfig(cfg)
|
||||||
_, err = s3client.PutObject(context.TODO(), &awss3.PutObjectInput{
|
_, err = s3client.PutObject(context.TODO(), &awss3.PutObjectInput{
|
||||||
Bucket: &bucket,
|
Bucket: &bucket,
|
||||||
Key: &filename,
|
Key: &filename,
|
||||||
ContentType: &mimeType,
|
ContentType: &mimeType,
|
||||||
ContentLength: &contentLength,
|
ContentLength: &contentLength,
|
||||||
Body: r,
|
Body: r,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to upload to s3 api: %v", err)
|
return "", fmt.Errorf("failed to upload to s3 api: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return filename, nil
|
return filename, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue