1
0
Fork 0

Implement random prefix

upload-progress
Ambrose Chua 2021-05-23 18:14:27 +08:00
parent 8c8abdce31
commit b89e415690
1 changed files with 11 additions and 1 deletions

View File

@ -7,10 +7,20 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
"github.com/gorilla/mux"
gonanoid "github.com/matoous/go-nanoid/v2"
)
func formatKey(prefix, filename string) string {
for strings.Contains(prefix, "{random}") {
random := gonanoid.MustGenerate(idAlphabet, 16)
prefix = strings.Replace(prefix, "{random}", random, 1)
}
return prefix + filename
}
/* createMultipartUpload */
type createMultipartUploadReq struct {
@ -59,7 +69,7 @@ func handleCreateMultipartUpload(w http.ResponseWriter, req *http.Request) {
}
// Derive the object key
key := cred.Prefix + r.Filename
key := formatKey(cred.Prefix, r.Filename)
result, err := initiateMultipartUpload(key, cred)
if err != nil {